javascript - Instantly detect an input being checked -
say have input type "checkbox"
<input type='checkbox' id='checker'>
i need able detect instantly whether box checked, without button click or function call. checking , unchecking box lighten or darken text. how check whether box unchecked or not in vanilla javascript? need able this, preferably without infinite for-loop that'll crash page. know method it
var value=document.getelementbyid('checker').checked;
but need way see whether has been checked or not without reloading page using vanilla javascript. please help!
edit: considering using 2 radio buttons, 1 value true , other value false, still need way of seeing 1 checked.
check working demo: http://jsfiddle.net/rrath8tg/1/:
// checkbox reference element checkbox.onchange = function() { if(this.checked) { // when checked } };
or onchange
on checkbox element.
Comments
Post a Comment