Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I do this with checkboxes?

Status
Not open for further replies.

bill120

IS-IT--Management
Oct 9, 2000
1
JP
Hi

I need to redirect a user to certain pages depending on the number of checkboxes checked. It does not matter which boxes are checked only the number.
i.e. 0-5 boxes checked go to page1, 6-10 boxes checked go to page2, 11-15 boxes checked go to page3.
Is there anyone who is willing to help me?
I am a newbie to javascript and not sure how to do this.
Please help me.

[sig][/sig]
 
Heres a script that works (in IE5 anyway).


<html>
<head>
<title>Checkboxes</title>

<script>
<!--

function cntBox () {
var nobox = 0;
for (i=0;i<myform.elements.length;i++)
{
if (document.myform.elements.checked) nobox++;
}

if (nobox < 6) window.location = 'pageone.html';
else if (nobox > 10) window.location = 'pagethree.html';
else window.location = 'pagetwo.html';

}

-->
</script>
</head>

<body>
<form name=&quot;myform&quot;>
<table cellpadding=&quot;0&quot; width=&quot;100%&quot;>
<tr>
<td><input type=&quot;checkbox&quot; name=&quot;box1&quot;>Box 1</td>
<td><input type=&quot;checkbox&quot; name=&quot;box2&quot;>Box 2</td>
<td><input type=&quot;checkbox&quot; name=&quot;box3&quot;>Box 3</td>
<td><input type=&quot;checkbox&quot; name=&quot;box4&quot;>Box 4</td>
<td><input type=&quot;checkbox&quot; name=&quot;box5&quot;>Box 5</td>
<td><input type=&quot;checkbox&quot; name=&quot;box6&quot;>Box 6</td>
<td><input type=&quot;checkbox&quot; name=&quot;box7&quot;>Box 7</td>
<td><input type=&quot;checkbox&quot; name=&quot;box8&quot;>Box 8</td>
<td><input type=&quot;checkbox&quot; name=&quot;box9&quot;>Box 9</td>
<td><input type=&quot;checkbox&quot; name=&quot;box10&quot;>Box 10</td>
<td><input type=&quot;checkbox&quot; name=&quot;box11&quot;>Box 11</td>
<td><input type=&quot;checkbox&quot; name=&quot;box12&quot;>Box 12</td>
<td><input type=&quot;checkbox&quot; name=&quot;box13&quot;>Box 13</td>
<td><input type=&quot;checkbox&quot; name=&quot;box14&quot;>Box 14</td>
<td><input type=&quot;checkbox&quot; name=&quot;box15&quot;>Box 15</td>
</tr>
<tr>
<td colspan=&quot;15&quot;>
<input type=&quot;button&quot; value=&quot;Count&quot; onClick=&quot;cntBox();&quot;>
</td>
</tr>
</table>
</form>

</body>
</html>


Enjoy :) [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top