I work on asp.net MVC app . I face issue checkbox value not detected changing value from true to false or reverse .
meaning if I change checkbox Value from Yes to No OR No to Yes nothing detected according to speakstuff property model .
Exactly I need when checkbox check for yes then true and if check box for No will be false .
html script represent yes or No check box
@Html.Label("Did You Meet/Speak to Staff", htmlAttributes: new { @class = "control-label col-md-5" })
Yes
NoAnd below is jQuery to allow only selection with yes or no
$(document).ready(function () {
$('.speak-stuff-checkbox').on('change', function () {
$('.speak-stuff-checkbox').not(this).prop('checked', false);
});
});I access value from form by java script
function submit() {
var ResignationRequester = new Object();
ResignationRequester.SpeakStuff = document.getElementById("SpeakStuff").value;model that represent property SpeakStuff
public class ResignationRequester
{
[Display(Name = "Employee No : ")]
[Required]
public int EmpID { get; set; }
[Display(Name = "Request No")]
public int RequestNo { get; set; }
public bool SpeakStuff { get; set; }
}and When click approve button and check speakstuff property it still not changed
using (Html.BeginForm("ApprovalIndex", "Resignation", new { id = Model.RequestNo }, FormMethod.Post, htmlAttributes: new { @style = "display:inline;" }))
{
Approve
}when debug model ResignationRequester speakstuff property it still true on all cases and if I change check box selection it still without change .
//post action method type
public async Task ApprovalIndex(ResignationRequester REQ)
{
}So How to solve this issue ?

Tahir AnsariRank #366 · 6.8K reputationPosted Oct 16, 2023, 3:11 AM EDT
$(document).ready(function () { $('.speak-stuff-checkbox').on('change', function () { $('.speak-stuff-checkbox').not(this).prop('checked', false); // Update the value of the SpeakStuff input based on the selected checkbox var selectedValue = $(this).val(); $('#SpeakStuff').val(selectedValue); }); });With this script, when the user selects "Yes" or "No," the
SpeakStuffinput's value will be updated accordingly. This will ensure that when the form is submitted, the value of theSpeakStuffproperty in your model will betrueorfalsebased on the user's selection.Tahir AnsariRank #366 · 6.8K reputationPosted Oct 16, 2023, 3:16 AM EDT
function submit() { var ResignationRequester = new Object(); // Check the state of the checkbox ResignationRequester.SpeakStuff = document.getElementById("SpeakStuff").checked; // Now, you have the correct boolean value for SpeakStuff }With this change, the
ResignationRequester.SpeakStuffproperty will correctly represent the checkbox state astruewhen the checkbox is checked andfalsewhen it's unchecked.