Reputation: 35
I have made one checkbox and I have two values like 1 for "yes" and 0 for "No". I want to pass two values for one checkbox . Is this possible?
<input type="checkbox" class="checkbox" id="checked" value="">
<label class="label" for="checked"></label>
On this checkbox when I click it turns to no ( means 0 value will return)
If it would be possible with javascript then best for me .
Upvotes: 0
Views: 575
Reputation: 405
I would solve this by adding a hidden input
<input type="hidden" .../>
and then on submit event of the form fill in the value based on the checkbox being checked or not. Use the value of the input instead of the checkbox in the form handling.
Upvotes: 0
Reputation: 943510
No. A checkbox will only send a value if it is checked.
Have your server side code test for the presence or absence of the value, not for a specific value.
Alternatively, use a pair of radio buttons.
Upvotes: 1