Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checkbox always On

Tags:

javascript

Why this code always alert "on"? No matter if it's checked or unchecked, it always print on.

click:
<input type="checkbox" onclick="alert(this.value)" />

http://jsfiddle.net/5yn78jhz/

like image 841
Savrige Avatar asked Dec 02 '22 18:12

Savrige


1 Answers

Use "this.checked" instead of "value" to get true or false for checked or unchecked.

like image 124
ynnus Avatar answered Jan 05 '23 20:01

ynnus