Accessing Check Boxes


f.elements["chkbox"].checked ?   "checked." : "not checked." 

An HTML check box knows only two states: checked and not checked. So when you're working with JavaScript, accessing this state is the most commonly used scenario.

The checked property of the check box is a Boolean value returning TRue if the check box is checked, and false otherwise. The following code shows this in context:

Accessing a Check Box (checkbox.html)

<script language="JavaScript"   type="text/javascript"> function showStatus(f) {   window.alert("The checkbox is " +     (f.elements["chkbox"].checked ?       "checked." : "not checked.")); } </script> <form>   <input type="checkbox" name="chkbox" />   <input type="button" value="Show status"     onclick="showStatus(this.form);" /> </form> 




JavaScript Phrasebook(c) Essential Code and Commands
JavaScript Phrasebook
ISBN: 0672328801
EAN: 2147483647
Year: 2006
Pages: 178

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net