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
Post a Comment