4

Deselect a default check box

 2 years ago
source link: https://www.codesd.com/item/deselect-a-default-check-box.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Deselect a default check box

advertisements

I want to create a checkbox which is unchecked always by default and users should not check it. I don't want to make the checkbox disabled as i want to pass the value of the checkbox when i submit the form. Please suggest. The below code is not working:

<input type="checkbox" id="chkbox1" name="chkbox1" value="unChecked" checked="false" readonly="readonly">

With the above code checkbox is always selected, i want the checkbox always be unselected and users should not able to select it.I should not use the disable option too as i want to send the value of checkbox when i submit the form.Thanks.


Just remove the checked attribute all together

<input type="checkbox" id="chkbox1" name="chkbox1" value="unChecked" readonly="readonly" />

Setting the checked attribute with any string value (even false) makes the checkbox checked


i want the checkbox always be unselected and users should not able to select it.I should not use the disable option too as i want to send the value of checkbox when i submit the form

It doesn't really sound like you want a checkbox at all, but just a hidden input that sends a value

<input type="hidden" name="chkbox1" value="unChecked" />




About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK