javascript - onchange event on checkbox always shows this.value = on -


an input of type checkbox when fires onchange event this.value set on when checkbox ticked off in case i'd expect off

is intended behavior?

<input type="checkbox" onchange="alert(this.value)">

short answer: not use value check checked status on checkboxes, use checked instead

<input type="checkbox" onchange="alert(this.checked)">

and in case wonder why always-"on" value, there's specification in html5 specification:

default/on

on getting, if element has value attribute, must return attribute's value; otherwise, it must return the string "on". on setting, must set element's value attribute new value.

http://www.w3.org/tr/html5/forms.html#dom-input-value-default-on


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -