I work on asp.net mvc I face issue i can't store value of health status on hidden field using jQuery then pass hidden field value after get value to approve () function when click agree button click on hidden field i will assign value true when checkbox Yes checked and assign value false when check box No checked then after hidden field get value true or false i will pass it to approve function java script when click button agree i'm not use hidden field before so can you help me please
@Html.Label("HealthStatus?", htmlAttributes: new { @class = "control-label col-md-5" })
Yes
No
agree
on csharp property HealthStatus is boolean as below
public class HealthStatusData
{
public bool? HealthStatus {get;set;}
}
so how to create hidden field then assign value of Healthstatus to hidden field using jQuery
$('.healthstatus-checkbox').on('change', function () {
// how to assign value to hidden field
});
then after that pass to approve function java script
Naimish MakwanaPosted Jan 22, 2024, 5:23 AM
You can create a hidden field in your HTML and then use jQuery to update the value of the hidden field based on the checkbox selection. Here’s how you can do it:
First, add a hidden field to your HTML:
Then, update your jQuery code to set the value of the hidden field when the checkbox value changes:
Finally, in your
approvefunction, you can get the value of the hidden field like this:This code will set the
HealthStatusproperty ofHealthStatusDatatotrueif the hidden field value is ‘true’, andfalseotherwise. Please note that the hidden field stores its value as a string, so we need to compare it with the string ‘true’ to get a boolean value. IThanks