Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Core Blazor: How to get the Checkbox value if it is checked?

I am trying to find to get the checkbox value if it is checked using Blazor framework, but I couldn't find any method for it so far. When I put the binding in the checkbox, it is always checked. I couldn't figured it out how to get the checked value.

This is my code:

<input type="checkbox" id="addition" name="math" value="add" bind="@name" /> <label for="addition">Addition</label> 
like image 578
jorjj Avatar asked Jul 08 '18 17:07

jorjj


People also ask

What is the value of check box if we checked the check box?

If a checkbox is marked or checked, it indicates to true; this means that the user has selected the value. If a checkbox is unmarked or not checked, it indicated to false; this means that the user has not selected the value.

What is the way to get the checked status of checkbox?

To get the state of a checkbox, you follow these steps: First, select the checkbox using a DOM method such as getElementById() or querySelector() . Then, access the checked property of the checkbox element. If its checked property is true , then the checkbox is checked; otherwise, it is not.

How do you bind a checkbox value in Blazor?

You can check/uncheck the checkbox in the Blazor programmatically by using the @bind parameter in the checkbox. Assign a Boolean property to @bind in the checkbox and toggle the Boolean property programmatically.

How do I get the value of the checkbox in Python?

Build A Paint Program With TKinter and Python To print the value of the selected checkbox, we can use the get() method. It returns the input value of a particular widget.


1 Answers

@page "/registration"      @foreach (var club in ClubList())     {         <input type="checkbox" @onchange="eventArgs => { CheckboxClicked(club, eventArgs.Value); }" />@club<br />     }  @functions {      public List<string> ClubMember { get; set; } = new List<string>();     void CheckboxClicked(string clubID, object checkedValue)     {         if ((bool)checkedValue)         {             if (!ClubMember.Contains(clubID))             {                 ClubMember.Add(clubID);             }         }         else         {             if (ClubMember.Contains(clubID))             {                 ClubMember.Remove(clubID);             }         }     }      public List<String> ClubList()     {         // fetch from API or...         List<String> c = new List<String>();         c.Add("Clube01");         c.Add("Clube02");         return c;     }  } 
like image 114
Manuel Alves Avatar answered Sep 20 '22 21:09

Manuel Alves