How to change checkbox selection using javascript?
or
What are the events associated with checkbox?
| Event Handler | Description | Example |
| onMouseOver | This is invoked whena mouse is moved over the checkbox | <input type=checkbox onMouseOver="output()"> Result : CB1 |
| onMouseDown | This is invoked when a mouse is pressed down on the checkbox | <input type=checkbox onMouseDown="output()"> Result : CB1 |
| onMouseUp | This is invoked when a mouse is pressed down on the checkbox and released | <input type=checkbox onMouseUp="output()"> Result : CB1 |
| onClick | onClick is invoked whena mouse click is done on the checkbox | <input type=checkbox onClick="output()"> Result : CB1 |
| onBlur | Executes some code when the check box loses focus using tab | <input type=checkbox onBlur="output()"> Result : CB1 |
| onFocus | Executes some code when the check box gets the focus using tab | <input type=checkbox onFocus="output()"> Result : CB1 |
| DOM Property | Description | Example |
| checked | Used to check or select checkbox. Each element has to be checked individually. The element if selected will return true else false. | To Check: var ss = document.testb.mycb[0].checked; var ss1 = document.testb.mycb[1].checked; To Select: document.testb.mycb[0].checked = true; |
| defaultChecked | Used to check whether the check box is selected by default | To Get: var ss = document.testb.mycb[0].defaultChecked; |
| form | Used to get the parent node (form object) of this check box | To Get: var ss = document.testb.mycb[0].form; |
| name | Used to get checkbox name | To Get: var ss = document.testb.mycb[0].name; |
| type | Used to get form type | To Get: var ss = document.testb.mycb[0].type; |
| value | Used to set or get checkbox value | To Get: var ss = document.testb.mycb[0].value; To Set:: document.testb.mycb[0].value = "testy"; |
| DOM Method | Description | Example |
| click() | Used to dynamically make a checkbox checked | To Click: document.testb.mycb.click(); |
| blur() | Used to dynamically make the check box blur | To Blur: document.testb.mycb.blur(); |
| focus() | Used to dynamically get focus on the check box | To Focus: document.testb.mycb.focus(); |