|
'this' is a javascript reserved word. For the most part it acts like a pointer and refers to whatever element it is in. It can also be used to point to some other element within the object's tree
'alert(this.checked)' --> the 'this' means the checkbox element/object
="doit(this.form)"> --> the 'this' means the button element and thus the form in which the button is found.
msg = (theObj.checked) ? "it's checked" : "it's not checked";
variable = (true/false conditional statement) ? ''result if condition is true" : "result if condition is false";
The first doit() function is called with onclick event handlers -- only the element concerned is being sent as a parameter so it's checked property can be tested immediately.
the second doit() function is called later (through the button). Since the entire form is passed, it is necessary to loop through the form's elements and find the desired objects (in actual code more testing would probably be necessary) Once found, the object's checked property is tested. (btw: Radios, by default, are arrays and any group of elements that have the same name will also be considered arrays by javascript -- and virtually every other language I know )
Vinny
|