Hi,
I am new to javascript. I want to select all the checkboxes or deselect all in a form, based on the state of one checkbox. Here is the code:
[HTML]<html>
<script language="JavaS cript">
function toggleChecked(o Element) {
oForm = oElement.form;
oElement = oForm.elements[oElement.name];
alert("oElement :"+ oElement.length );
if(oElement.len gth) {
bChecked = oElement[0].checked;
for(i = 1; i < oElement.length ; i++)
oElement[i].checked = bChecked;
}
}
</script>
<form action="JavaScr ipt:" onsubmit="retur n false">
<INPUT TYPE=CHECKBOX NAME="checkall" value="checkall " onClick="toggle Checked(this)"/>Check all<BR>
<INPUT TYPE=CHECKBOX NAME="mushrooms " value="mushroom s">mushrooms<BR >
<INPUT TYPE=CHECKBOX NAME="greenpepp ers" value="greenpep pers">green peppers<BR>
<INPUT TYPE=CHECKBOX NAME="olives" value="olives"> olives<BR>
<INPUT TYPE=CHECKBOX NAME="onions" value=""onions> onions<P>
<INPUT TYPE=SUBMIT VALUE="submit">
</form>
</html>[/HTML]
But I am getting the form value as null and no length inside the javascript.
Please help. Thanks in advance.
I am new to javascript. I want to select all the checkboxes or deselect all in a form, based on the state of one checkbox. Here is the code:
[HTML]<html>
<script language="JavaS cript">
function toggleChecked(o Element) {
oForm = oElement.form;
oElement = oForm.elements[oElement.name];
alert("oElement :"+ oElement.length );
if(oElement.len gth) {
bChecked = oElement[0].checked;
for(i = 1; i < oElement.length ; i++)
oElement[i].checked = bChecked;
}
}
</script>
<form action="JavaScr ipt:" onsubmit="retur n false">
<INPUT TYPE=CHECKBOX NAME="checkall" value="checkall " onClick="toggle Checked(this)"/>Check all<BR>
<INPUT TYPE=CHECKBOX NAME="mushrooms " value="mushroom s">mushrooms<BR >
<INPUT TYPE=CHECKBOX NAME="greenpepp ers" value="greenpep pers">green peppers<BR>
<INPUT TYPE=CHECKBOX NAME="olives" value="olives"> olives<BR>
<INPUT TYPE=CHECKBOX NAME="onions" value=""onions> onions<P>
<INPUT TYPE=SUBMIT VALUE="submit">
</form>
</html>[/HTML]
But I am getting the form value as null and no length inside the javascript.
Please help. Thanks in advance.
Comment