javascript - Checkbox value: optional or required? -



javascript - Checkbox value: optional or required? -

according mdn value attribute optional except when value of type attribute radio or checkbox. doesn't seem correct. there wrong following:

<input type="checkbox" id="input"> <script> document.getelementbyid('input').onchange = function () { alert('checked!'); }; </script>

demo

the value attribute required if want checkbox post through value when submit form. if you're not submitting form want know when it's clicked, there's nil wrong example.

note illustration alert "checked!" when user un-checks box too. that's why might want @ value of checked attribute in javascript.

javascript html checkbox

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -