HTML Tutorial


 Forum HomeForum Home   FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
RegisterRegister - Not registered yet? Got something to say? Join HTML Code Tutorial!
Combination of 4 Check Boxes
Post new topic   Reply to topic    HTML Help Forum Index -> Javascript
View previous topic :: View next topic  
Author Message
PiperJim



Joined: 01 Dec 2007
Posts: 6

PostPosted: Sat Dec 01, 2007 1:34 am     Combination of 4 Check Boxes Reply with quote

I wish to set up a page with 4 check boxes so that you can select a combination of all 4 boxes A, B, C, D.
(ie) By selecting A you will go to a page title A
By selecting A,C you will go to a page title AC and so on
is this possible with javascript as I have been looking for a program for a few days now with no success

Thanks PiperJim
camoman666



Joined: 24 Jun 2006
Posts: 373
Location: Fort Walton Beach, FL, USA

PostPosted: Sun Dec 02, 2007 10:33 am     Reply with quote

Chose one of either the Brute Force JavaScript or the Simple JavaScript function and paste it into your HEAD section.

JavaScript (Brute Force):
Code:
<script type="text/JavaScript">
<!--
var a = 0;
var b = 0;
var c = 0;
var d = 0;
var page;
function route(){
 if(document.boxes.a.checked==true){
  a = 1;
 }
 if(document.boxes.b.checked==true){
  b = 1;
 }
 if(document.boxes.c.checked==true){
  c = 1;
 }
 if(document.boxes.d.checked==true){
  d = 1;
 }
 if(a){
  if(b){
   if(c){
    if(d){
     page = "abcd.html";
    }else{
     page = "abc.html";
    }
   }else{
    if(d){
     page = "abd.html";
    }else{
     page = "ab.html";
    }
  }else{
   if(c){
    if(d){
     page = "acd.html";
    }else{
     page = "ac.html";
    }
   }else{
    if(d){
     page = "ad.html";
    }else{
     page = "a.html";
    }
   }
  }
 }else{
  if(b){
   if(c){
    if(d){
     page = "bcd.html";
    }else{
     page = "bc.html";
    }
   }else{
    if(d){
     page = "bd.html";
    }else{
     page = "b.html";
    }
   }
  }else{
   if(c){
    if(d){
     page = "cd.html";
    }else{
     page = "c.html";
    }
   }else{
    if(d){
     page = "d.html";
    }else{
     page = "none.html";
    }
   }
  }
 }
 window.location = page;
}
-->
</script>


JavaScript (Simple):
Code:
<script type="text/JavaScript">
<!--
var page = "";
function route(){
 if(document.boxes.a.checked==true){
  page = "a";
 }
 if(document.boxes.b.checked==true){
  page = page + "b";
 }
 if(document.boxes.c.checked==true){
  page = page + "c";
 }
 if(document.boxes.d.checked==true){
  page = page + "d";
 }
 if(page==""){
  page = "none.html";
 }else{
  page = page + ".html";
 }
 window.location = page;
}
-->
</script>


Form:
Code:
<form name="boxes" action="javascript:route()">
 <input type="checkbox" name="a">
 <input type="checkbox" name="b">
 <input type="checkbox" name="c">
 <input type="checkbox" name="d">
 <input type=submit value="Submit">
</form>


Either JavaScript method will work, but the seccond one will take up less memory on your server.
PiperJim



Joined: 01 Dec 2007
Posts: 6

PostPosted: Sun Dec 02, 2007 12:18 pm     Thanks Reply with quote

Thank you camoman666
Thats great and perfect
Many, many, many, thanks
camoman666



Joined: 24 Jun 2006
Posts: 373
Location: Fort Walton Beach, FL, USA

PostPosted: Sun Dec 02, 2007 12:36 pm     Reply with quote

It's no problem, I'm always glad to help.
Display posts from previous:   
Post new topic   Reply to topic    HTML Help Forum Index -> Javascript All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
HTML Help Archive
Powered by phpBB © 2001, 2005 phpBB Group
HTML Help topic RSS feed 

 
DARFUR
HOSTING / DESIGN
MAKE MONEY

Home
  |   Tutorials   |   Forum   |   Quick List   |   Link Directory   |   About
Copyright ©1997-2002 Idocs and ©2002-2007 HTML Code Tutorial