Link to home
Start Free TrialLog in
Avatar of Panoscha32
Panoscha32

asked on

checkboxes - vbscript or javascript

hello there! I have in an ASP file the following checkboxes:

<input type="checkbox">Choice 1<br>
<input type="checkbox">Choice 2<br>
<input type="checkbox">Choice 3<br>
<p>
<input type="checkbox">Checked<br>
<input type="checkbox">Unchecked
</p>

I want each time I select the 'Checked' checkbox, Choice1, Choise2 and Choice3 boxes to be selected. And each time I select 'Unchecked' the three previous to be unselected.
ASKER CERTIFIED SOLUTION
Avatar of AlfaNoMore
AlfaNoMore

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AlfaNoMore
AlfaNoMore

Or, if you had more Choice's to check, you could try a simple loop:


function CheckAll() {
   for(i=1; i<4; i++) {
      eval('document.forms[0].Choice' + i + '.checked = true');
   }
}
Avatar of Panoscha32

ASKER

Looks good but for some reason it doesn't work. I receive at the buttom of my browser this annoying message 'Error on page'.
OK i found it. Thanks very much. The only ommission was that:

<form method="post"><form>

inside <body> section. So here it goes:

<html>
<head>
<title>some title</title>

<script language="javascript">
<!--
function CheckAll() {
   document.forms[0].Choice1.checked = true;
   document.forms[0].Choice2.checked = true;
   document.forms[0].Choice3.checked = true;
}

function UnCheckAll() {
   document.forms[0].Choice1.checked = false;
   document.forms[0].Choice2.checked = false;
   document.forms[0].Choice3.checked = false;
}
//-->
</script>

</head>

<body>
<form method="post">
<input type="checkbox" NAME="Choice1">Choice 1<br>
<input type="checkbox" NAME="Choice2">Choice 2<br>
<input type="checkbox" NAME="Choice3">Choice 3<br>
<p>
<input type="checkbox" NAME="AllCheck" onClick="CheckAll();">Checked<br>
<input type="checkbox" NAME="AllUnCheck" onClick="UnCheckAll();">Unchecked
</p>
</form>
<body>

</html>