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!

Combining Multiple Checkboxes to call Separate Web Pages

Status
Not open for further replies.

compuv

MIS
Mar 16, 2002
10
GB
How do I send a user to a separate web page depending on what combination of checkboxes are clicked? e.g. if I've got 3 checkboxes then I'll have 7 different pages (ignoring all boxes being left blank). This is driving me mad so I'd appreciate any suggestions.
 
that's a great ... problem

look, if you have 6 checkboxes you get ... (1,6)+(2,6)+(3,6)+(4,6)+(5,6)+(6,6) different combinations witch is a true mess.

well the case of 3, is simple (more or less)

function nextpage(){
var comb=0;
if (!myform.check1.checked && !myform.check2.checked && !myform.check3.checked)
myform.action="action1.html";
elseif (!myform.check1.checked && !myform.check2.checked && myform.check3.checked)
myform.action="action2.html";
...

myform.submit();
}

remind one thing, this is like binary, with 3 checks you get 8 possibilities, with 4/16, 5/32, and so on.

Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Hi Compuv,

Try this solution. You can easily make it to 4 checkboxes. You only have to add the 4th checkbox and the variables d, ad, bd, cd, abd, acd, bcd, abcd LOL
Of course Anikin is right about having 5 checkboxes or more

Here is my code. I hope you like it:

<html>
<head>
</head>

<body>

<script language=&quot;javascript&quot;>
function opensite()
{
var endvalue = &quot;&quot;;
var DM = document.MyForm1;
var NrCbs = DM.cb1.length;
var a = &quot;google.com&quot;;
var b = &quot;yahoo.com&quot;;
var c = &quot;CNN.com&quot;;
var ab= &quot;microsoft.com&quot;;
var ac= &quot;netscape.com&quot;;
var bc = &quot;W3.org&quot;;
var abc = &quot;tek-tips.com&quot;;
var preURL = &quot;
for (ia = parseInt(0); ia < NrCbs; ia++)
{
if (DM.cb1[ia].checked)
endvalue = endvalue + DM.cb1[ia].value;
}

defURL = eval(&quot;'&quot; + preURL + eval(endvalue) + &quot;'&quot;);

if (!endvalue == &quot;&quot;)
{
window.open(defURL, 'windowname3','toolbar=yes, location=yes, directories=yes, status=yes, menubar=yes, resizable=yes, scrollbars=yes, top=0, left=0, height=600, width=800');
}
else
{
alert(&quot;no checkboxes are selected&quot;)
}
}
</script>

<form name=&quot;MyForm1&quot;>
a: <INPUT TYPE=&quot;checkbox&quot; value=&quot;a&quot; name=cb1>
b: <INPUT TYPE=&quot;checkbox&quot; value=&quot;b&quot; name=cb1>
c: <INPUT TYPE=&quot;checkbox&quot; value=&quot;c&quot; name=cb1>
<br>
<input type=&quot;submit&quot; value=&quot;go to the site&quot; name=&quot;submit777&quot; ONCLICK=&quot;opensite()&quot;>
</form>

</body>
</html>

Hope this helps,
Erik
<!-- My sport: Boomerang throwing !!
This year I will participate at the World Championships in Germany. (!! Many Happy Returns !! -->
 
Many thanks for such prompt responses, guys. I'll away and put your suggestions to work.

Much appreciated!

Dave
 
Just out of curiosity, WHY?
[ponder]
Would it not be easier to list the various URLs and have the user pick to one they want to go to?



 
It would be normally, Turkbear, but for this project I have to let people select what they want. It would just be a bit messy with loads of URL's all over the place, especially when they're titled &quot;click here if you want this and that but not the other, etc.&quot;
 
Oh, I forgot about user expectations [smile]

Perhaps a little user training about what is feasable is in order, because this method could get way out of hand..
[profile]

 
This would be a great security feature (if it wasn't client side script). You could have just a page with a bunch of checkboxes and one button. The only way to get to the next page is know the correct checkboxes to select. Unfortunately anyone that knows &quot;view source&quot; would be able to determine the correct boxes and the &quot;trick&quot; is up.

But in theory that sure sounds fun [spidey] Einstein47
(Love is like PI - natural, irrational, endless, and very important.)
 
Thanks for the code, Boomerang. I'm having a wee bit of a problem though. I've set a test page up at Clicking on the button gives &quot; in the address bar but you don't actually go anywhere! Am I missing something obvious? I've been through the code with a toothcomb but can't see what could be wrong.

Dave
 
Hi Dave,

For some reason tek-tips add an exra visible semisolon (;) and an extra &quot;unvisible&quot; slash (/) to a row in your post that includes an URL.

So the row [ignore]var preURL = &quot;[/ignore] I typed was changed to [ignore]var preURL = &quot;[/ignore] shown in my post and changed to [ignore]var preURL = &quot;[/ignore] when you do a copy and paste.

So this is the right code:
[ignore]var preURL = &quot;[/ignore]

Now it should work,
Erik

p.s.
for all members who want to know how to avoid these extra characters in a post:
type &#91;ignore&#93;[ignore]var preURL = &quot;[/ignore]&#91;/ignore&#93;

<!-- My sport: Boomerang throwing !!
This year I will participate at the World Championships in Germany. (!! Many Happy Returns !! -->
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top