Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (20.3k points)

I've got a load of checkboxes that are checked by default. My users will probably uncheck a few (if any) of the checkboxes and leave the rest checked.

Is there any way to make the form POST the checkboxes that are not checked, rather than the ones that are checked?

1 Answer

0 votes
by (40.7k points)

You can try adding a hidden input for the checkbox with a different ID like this:

<input id='testName' type='checkbox' value='Yes' name='testName'>

<input id='testNameHidden' type='hidden' value='No' name='testName'>

But, before submitting the form you can just disable the hidden input based on the checked condition this way:

if(document.getElementById("testName").checked) {

    document.getElementById('testNameHidden').disabled = true;

}

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...