I'm trying to search for the correct code to make my form work. I have 3 select boxes - one with 2 options, one with 8 options, and the last with 2 options... All of this adds up to 32 different url paths. Can anyone tell me how to get this done?

This is what I have so far: (and yea, I know I suck... I honestly have absolutely NO clue)

<html> 
<head> 
<script> 
url = new Array(); 
url[0] = new Array(); 
url[0][0][0] = 'http://www.URL1.com'; 
url[0][1][0] = 'http://www.URL2.com'; 
url[0][2][0] = 'http://www.URL3.com'; 
url[0][3][0] = 'http://www.URL4.com'; 
url[0][4][0] = 'http://www.URL5.com'; 
url[0][5][0] = 'http://www.URL6.com'; 
url[0][6][0] = 'http://www.URL7.com'; 
url[0][7][0] = 'http://www.URL8.com'; 
url[0][0][1] = 'http://www.URL9.com'; 
url[0][1][1] = 'http://www.URL10.com'; 
url[0][2][1] = 'http://www.URL11.com'; 
url[0][3][1] = 'http://www.URL12.com'; 
url[0][4][1] = 'http://www.URL13.com'; 
url[0][5][1] = 'http://www.URL14.com'; 
url[0][6][1] = 'http://www.URL15.com'; 
url[0][7][1] = 'http://www.URL16.com'; 


url[1] = new Array(); 
url[1][0][0] = 'http://www.URL17.com'; 
url[1][1][0] = 'http://www.URL18.com'; 
url[1][2][0] = 'http://www.URL19.com'; 
url[1][3][0] = 'http://www.URL20.com'; 
url[1][4][0] = 'http://www.URL21.com'; 
url[1][5][0] = 'http://www.URL22.com'; 
url[1][6][0] = 'http://www.URL23.com'; 
url[1][7][0] = 'http://www.URL24.com'; 
url[1][0][1] = 'http://www.URL25.com'; 
url[1][1][1] = 'http://www.URL26.com'; 
url[1][2][1] = 'http://www.URL27.com'; 
url[1][3][1] = 'http://www.URL28.com'; 
url[1][4][1] = 'http://www.URL29.com'; 
url[1][5][1] = 'http://www.URL30.com'; 
url[1][6][1] = 'http://www.URL31.com'; 
url[1][7][1] = 'http://www.URL32.com'; 



function newURL(){ 
d = document.forms[0];p2 =-1;p1 =-1; 
for(i=0;i<d.ch.length;i++){ 
if (d.ch[i].checked){ 
if(p2 == 1){ 
if(i == d.ch.length-1){alert('There is no url for this combination!');return false} 
else {p1 = 0;break} 
} 
else {p1 = i;p2++;}}}
if(p2 == -1){alert('Please select all fields!'); return false} 
window.open(url[p1][p2],'_self'); 
} 
</script> 
</head> 

<body> 
<form> <select name="gender">
<OPTION value="1">Girl
<OPTION value="2">Boy</OPTION></select>
<select name="grade">
<OPTION value="1">3rd Grade
<OPTION value="2">4th Grade
<OPTION value="3">5th Grade
<OPTION value="4">6th Grade
<OPTION value="5">7th Grade
<OPTION value="6">8th Grade
<OPTION value="7">9th Grade
<OPTION value="8">10th Grade
</OPTION></select>
<select name="classroom">
<OPTION value="1">English
<OPTION value="2">Math
</OPTION></select>
<input type="button" onclick="return newURL()" value="Submit"> 
</form> 
</body> 
</html>

Thanks for your time.

Recommended Answers

All 2 Replies

<html> 
<head> 
<script> 

url = new Array(); 
url[0] = new Array(); 
url[0][0]=['http://www.URL1.com','http://www.URL9.com']; 
url[0][1]=['http://www.URL2.com','http://www.URL10.com']; 
url[0][2]=['http://www.URL3.com','http://www.URL11.com']; 
url[0][3]=['http://www.URL4.com','http://www.URL12.com']; 
url[0][4]=['http://www.URL5.com','http://www.URL13.com']; 
url[0][5]=['http://www.URL6.com','http://www.URL14.com']; 
url[0][6]=['http://www.URL7.com','http://www.URL15.com']; 
url[0][7]=['http://www.URL8.com','http://www.URL16.com']; 

url[1] = new Array(); 
url[1][0]=['http://www.URL17.com','http://www.URL25.com']; 
url[1][1]=['http://www.URL18.com','http://www.URL26.com']; 
url[1][2]=['http://www.URL19.com','http://www.URL27.com']; 
url[1][3]=['http://www.URL20.com','http://www.URL28.com']; 
url[1][4]=['http://www.URL21.com','http://www.URL29.com']; 
url[1][5]=['http://www.URL22.com','http://www.URL30.com']; 
url[1][6]=['http://www.URL23.com','http://www.URL31.com']; 
url[1][7]=['http://www.URL24.com','http://www.URL32.com']; 




function newURL(){
	var f=document.forms[0];
	try{
		var u = url[f.gender.selectedIndex][f.grade.selectedIndex][f.classroom.selectedIndex];
		alert(u);
		window.open(u,'_self');
	}catch(e){
		alert("All Fields are required");
	}
} 
</script> 
</head> 

<body> 
<form>
<select name="gender">
	<OPTION value="1">Girl</OPTION>
	<OPTION value="2">Boy</OPTION>
</select>

<select name="grade">
	<OPTION value="1">3rd Grade</OPTION>
	<OPTION value="2">4th Grade</OPTION>
	<OPTION value="3">5th Grade</OPTION>
	<OPTION value="4">6th Grade</OPTION>
	<OPTION value="5">7th Grade</OPTION>
	<OPTION value="6">8th Grade</OPTION>
	<OPTION value="7">9th Grade</OPTION>
	<OPTION value="8">10th Grade</OPTION>
</select>
<select name="classroom">
	<OPTION value="1">English</OPTION>
	<OPTION value="2">Math</OPTION>
</select>
<input type="button" onclick="return newURL()" value="Submit"> 
</form> 
</body> 
</html>

Thank you so much. It works great, and your layout is extremely clean and easy to follow.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.