Click here to Skip to main content
15,898,036 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
@Html.CheckBoxFor(model => model.EmployeeMaritalStatus, new { htmlAttributes = new { @class = "EmpMaritalStatus1", @id = "Married", @maxlength = "150" } }) Married  
@Html.CheckBoxFor(model => model.EmployeeMaritalStatus, new { htmlAttributes = new { @class = "EmpMaritalStatus2", @id = "Single", @maxlength = "150" } }) Single

What I have tried:

how to get id="Married" value using Jquery
Posted
Updated 2-Oct-19 1:49am
Comments
Richard Deeming 8-Aug-19 10:47am    
Can your employees be both married and single at the same time?

Probably not. So why allow the user to tick both options?

Use radio buttons instead of checkboxes - @Html.RadioButtonFor.

//Get Value
var MarriedVal = $('#Married').val();

//Set Value
$('#Married').val("SetValue");
 
Share this answer
 
You can get it by multiple ways.

1) By the input property as below.
var Married = $("input[type='checkbox']").val();
alert(Married);



2)By the just id name
$('#Married').val();



3)By checking the value of the check property of checkbox
if ($('#Married').is(":checked"))
{
  //can set static as below
  $('#Married').val('Married');
  //or can do you logic here
}
 
Share this answer
 
v2
var group = "input:checkbox[name='" + $(this).attr("name") + "']";
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900