PDA

View Full Version : checkboxes


phani
08-31-2002, 12:48 PM
hai,

iam having problem in checkboxes. i want to checkbox to be checked on clicking the button.i have to give the same name to each of the checkbox. it's working fine while giving different names to each checkbox. here is the code:



<script>
function check()
{
for (i=1;i<document.forms[0].elements.length-1;i++)
{
document.forms[0].checkbox1.checked=true;
}
}
</script>
<body>
<form>
<input type="checkbox" name="checkbox1" value=1>
<input type="checkbox" name="checkbox1" value=2>
<input type="checkbox" name="checkbox1" value=3>
<input type="checkbox" name="checkbox1" value=4>
<input type="button" value=check onclick="check()">
</form>
</body>

boywonder
08-31-2002, 03:19 PM
this should do it:
for (i=0;i<document.forms[0].checkbox1.length;i++){
document.forms[0].checkbox1[i].checked=true;
}

phani
09-01-2002, 05:41 AM
sorry it doesn't worked. It is showing errror as

"document.forms[0].checkbox1[..] is null or not an object"

boywonder
09-01-2002, 07:38 PM
It works just fine for me...

<html>
<head>
<title>Untitled</title>
</head>
<body>
<script>
function check() {
for (i=0;i<document.forms[0].checkbox1.length;i++) document.forms[0].checkbox1[i].checked=true;
}
</script>
<form>
<input type="checkbox" name="checkbox1" value=1>
<input type="checkbox" name="checkbox1" value=2>
<input type="checkbox" name="checkbox1" value=3>
<input type="checkbox" name="checkbox1" value=4>
<input type="button" value=check onclick="check();">
</form>
</body>
</html>

You are trying to check all the boxes of the same name with one click, right?

Do you have any other forms in the page before that one?

Post the code you have if you still get errors...

phani
09-02-2002, 05:23 AM
thank u i got it . It has worked fine