Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-05-2007, 01:14 AM   PM User | #1
Harveee
New to the CF scene

 
Join Date: Jul 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Harveee is an unknown quantity at this point
multiple dynamic combo boxes

Hi.

As a complete beginner i was wondering if there was a way to output the result of the third combo box in the multiple dyamic combo box code by Elviro Mirko to a text area.

I have tried to use the description event but to some effect but this wll not allow me to use hyperlinks in the end result.

any help would be greatly appreciated.

I have inserted Elviro's code below.

<script language="JavaScript" type="text/javascript">
<!--

/*
*** Multiple dynamic combo boxes
*** by Mirko Elviro, 9 Mar 2005
*** Script featured and available on JavaScript Kit (http://www.javascriptkit.com)
***
***Please do not remove this comment
*/

// This script supports an unlimited number of linked combo boxed
// Their id must be "combo_0", "combo_1", "combo_2" etc.
// Here you have to put the data that will fill the combo boxes
// ie. data_2_1 will be the first option in the second combo box
// when the first combo box has the second option selected


// first combo box

data_1 = new Option("1", "$");
data_2 = new Option("2", "$$");

// second combo box

data_1_1 = new Option("11", "-");
data_1_2 = new Option("12", "-");
data_2_1 = new Option("21", "--");
data_2_2 = new Option("22", "--");
data_2_3 = new Option("23", "--");
data_2_4 = new Option("24", "--");
data_2_5 = new Option("25", "--");

// third combo box

data_1_1_1 = new Option("111", "*");
data_1_1_2 = new Option("112", "*");
data_1_1_3 = new Option("113", "*");
data_1_2_1 = new Option("121", "*");
data_1_2_2 = new Option("122", "*");
data_1_2_3 = new Option("123", "*");
data_1_2_4 = new Option("124", "*");
data_2_1_1 = new Option("211", "**");
data_2_1_2 = new Option("212", "**");
data_2_2_1 = new Option("221", "**");
data_2_2_2 = new Option("222", "**");
data_2_3_1 = new Option("231", "***");
data_2_3_2 = new Option("232", "***");

// fourth combo box

data_2_2_1_1 = new Option("2211","%")
data_2_2_1_2 = new Option("2212","%%")

// other parameters

displaywhenempty=""
valuewhenempty=-1

displaywhennotempty="-select-"
valuewhennotempty=0


function change(currentbox) {
numb = currentbox.id.split("_");
currentbox = numb[1];

i=parseInt(currentbox)+1

// I empty all combo boxes following the current one

while ((eval("typeof(document.getElementById(\"combo_"+i+"\"))!='undefined'")) &&
(document.getElementById("combo_"+i)!=null)) {
son = document.getElementById("combo_"+i);
// I empty all options except the first one (it isn't allowed)
for (m=son.options.length-1;m>0;m--) son.options[m]=null;
// I reset the first option
son.options[0]=new Option(displaywhenempty,valuewhenempty)
i=i+1
}


// now I create the string with the "base" name ("stringa"), ie. "data_1_0"
// to which I'll add _0,_1,_2,_3 etc to obtain the name of the combo box to fill

stringa='data'
i=0
while ((eval("typeof(document.getElementById(\"combo_"+i+"\"))!='undefined'")) &&
(document.getElementById("combo_"+i)!=null)) {
eval("stringa=stringa+'_'+document.getElementById(\"combo_"+i+"\").selectedIndex")
if (i==currentbox) break;
i=i+1
}


// filling the "son" combo (if exists)

following=parseInt(currentbox)+1

if ((eval("typeof(document.getElementById(\"combo_"+following+"\"))!='undefined'")) &&
(document.getElementById("combo_"+following)!=null)) {
son = document.getElementById("combo_"+following);
stringa=stringa+"_"
i=0
while ((eval("typeof("+stringa+i+")!='undefined'")) || (i==0)) {

// if there are no options, I empty the first option of the "son" combo
// otherwise I put "-select-" in it

if ((i==0) && eval("typeof("+stringa+"0)=='undefined'"))
if (eval("typeof("+stringa+"1)=='undefined'"))
eval("son.options[0]=new Option(displaywhenempty,valuewhenempty)")
else
eval("son.options[0]=new Option(displaywhennotempty,valuewhennotempty)")
else
eval("son.options["+i+"]=new Option("+stringa+i+".text,"+stringa+i+".value)")
i=i+1
}
//son.focus()
i=1
combostatus=''
cstatus=stringa.split("_")
while (cstatus[i]!=null) {
combostatus=combostatus+cstatus[i]
i=i+1
}
return combostatus;
}
}

//-->
</script>

<form>
<select name="combo0" id="combo_0" onChange="change(this);" style="width:200px;">
<option value="value1">-select-</option>
<option value="value2">1</option>
<option value="value3">2</option>

</select>
<BR><BR>
<select name="combo1" id="combo_1" onChange="change(this)" style="width:200px;">
<option value="value1"> </option>
</select>
<BR><BR>
<select name="combo2" id="combo_2" onChange="change(this);" style="width:200px;">
<option value="value1"> </option>
</select>
<BR><BR>
<select name="combo3" id="combo_3" onChange="change(this);" style="width:200px;">
<option value="value1"> </option>

</select>

</form>

<p align="center"><font face="arial" size="-2">This free script provided by</font><br>
<font face="arial, helvetica" size="-2"><a href="http://javascriptkit.com">JavaScript
Kit</a></font></p>
Harveee is offline   Reply With Quote
Old 07-05-2007, 09:53 PM   PM User | #2
mcjwb
Regular Coder

 
Join Date: Jul 2007
Location: UK
Posts: 223
Thanks: 0
Thanked 14 Times in 14 Posts
mcjwb is an unknown quantity at this point
Quote:
I have tried to use the description event but to some effect but this wll not allow me to use hyperlinks in the end result.
Not entirely sure what you meant by "use the description event" but is this what you're after?

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title> New Document </title>
<script type="text/javascript">
<!--

/*
*** Multiple dynamic combo boxes
*** by Mirko Elviro, 9 Mar 2005
*** Script featured and available on JavaScript Kit (http://www.javascriptkit.com)
***
***Please do not remove this comment
*/

// This script supports an unlimited number of linked combo boxed
// Their id must be "combo_0", "combo_1", "combo_2" etc.
// Here you have to put the data that will fill the combo boxes
// ie. data_2_1 will be the first option in the second combo box
// when the first combo box has the second option selected


// first combo box

data_1 = new Option("1", "$");
data_2 = new Option("2", "$$");

// second combo box

data_1_1 = new Option("11", "-");
data_1_2 = new Option("12", "-");
data_2_1 = new Option("21", "--");
data_2_2 = new Option("22", "--");
data_2_3 = new Option("23", "--");
data_2_4 = new Option("24", "--");
data_2_5 = new Option("25", "--");

// third combo box

data_1_1_1 = new Option("111", "*");
data_1_1_2 = new Option("112", "*");
data_1_1_3 = new Option("113", "*");
data_1_2_1 = new Option("121", "*");
data_1_2_2 = new Option("122", "*");
data_1_2_3 = new Option("123", "*");
data_1_2_4 = new Option("124", "*");
data_2_1_1 = new Option("211", "**");
data_2_1_2 = new Option("212", "**");
data_2_2_1 = new Option("221", "**");
data_2_2_2 = new Option("222", "**");
data_2_3_1 = new Option("231", "***");
data_2_3_2 = new Option("232", "***");

// fourth combo box


data_2_2_1_1 = new Option("Google","http://www.google.co.uk");
data_2_2_1_2 = new Option("bbc","http://www.bbc.co.uk");

// other parameters

displaywhenempty="";
valuewhenempty=-1;

displaywhennotempty="-select-";
valuewhennotempty=0;


function change(currentbox) {
	numb = currentbox.id.split("_");
	currentbox = numb[1];

	i=parseInt(currentbox)+1;

	// I empty all combo boxes following the current one

	while (document.getElementById("combo_"+i)) {
		son = document.getElementById("combo_"+i);
		// I empty all options except the first one (it isn't allowed)
		for (m=son.options.length-1; m>0; m--) son.options[m]=null;
		// I reset the first option
		son.options[0]=new Option(displaywhenempty,valuewhenempty);
		i++;
	}


	// now I create the string with the "base" name ("stringa"), ie. "data_1_0"
	// to which I'll add _0,_1,_2,_3 etc to obtain the name of the combo box to fill

	stringa='data';
	i=0;
	while (document.getElementById("combo_"+i)) {
		stringa=stringa+'_'+document.getElementById("combo_"+i).selectedIndex;
		if (i==currentbox) break;
		i++;
	}


	// filling the "son" combo (if exists)

	following=parseInt(currentbox)+1;

	if (document.getElementById("combo_"+following)) {
		son = document.getElementById("combo_"+following);
		stringa=stringa+"_";
		i=0;
		while ((eval("typeof("+stringa+i+")!='undefined'")) || (i==0)) {

			// if there are no options, I empty the first option of the "son" combo
			// otherwise I put "-select-" in it

			if ((i==0) && eval("typeof("+stringa+"0)=='undefined'"))
				if (eval("typeof("+stringa+"1)=='undefined'"))
					son.options[0]=new Option(displaywhenempty,valuewhenempty);
				else
					son.options[0]=new Option(displaywhennotempty,valuewhennotempty);
			else
				son.options[i]=new Option(eval(stringa+i+".text"),eval(stringa+i+".value"));
			i++;
		}
		//son.focus()
		i=1;
		combostatus='';
		cstatus=stringa.split("_");
		while (cstatus[i]) {
			combostatus=combostatus+cstatus[i];
			i++;
		}
		return combostatus;
	}
}


function go(elementName){
	var newUrl=document.forms[0].elements[elementName].options[document.forms[0].elements[elementName].selectedIndex].value;
	if(newUrl.indexOf("www")>=0){//rudamentary url checker! So don't go to a blank page if select box not populated.
		location.href=newUrl;
	}
}
//-->
</script>
</head>
<body>

<form>
<select name="combo0" id="combo_0" onChange="change(this);" style="width:200px;">
<option value="value1">-select-</option>
<option value="value2">1</option>
<option value="value3">2</option>

</select>
<BR><BR>
<select name="combo1" id="combo_1" onChange="change(this)" style="width:200px;">
<option value="value1"> </option>
</select>
<BR><BR>
<select name="combo2" id="combo_2" onChange="change(this);" style="width:200px;">
<option value="value1"> </option>
</select>
<BR><BR>
<select name="combo3" id="combo_3" onChange="change(this);" style="width:200px;">
<option value="value1"> </option> <input type="button" value="Go" onclick="go('combo3')"><!-- could be changed for onchange event handler on select box -->

</select>

</form>

<p align="center"><font face="arial" size="-2">This free script provided by</font><br>
<font face="arial, helvetica" size="-2"><a href="http://javascriptkit.com">JavaScript
Kit</a></font></p>
</body>
</html>
Hope you and Mirko don't mind me modifying the script a bit!
mcjwb is offline   Reply With Quote
Old 07-06-2007, 12:31 AM   PM User | #3
Harveee
New to the CF scene

 
Join Date: Jul 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Harveee is an unknown quantity at this point
Hi mcjwb

Thank you for replying to my plea for help.

I have abandoned Mirko's code in favour of someone else' and have had a good hack about with it, but still can't get the desired result.

If you look at the England / North East / Advertising option, you can see how i have achieved my result, using the description to populate the textarea with the relevant info.

I realise it is very long winded, but i don't have the skill to use .asp / mysql etc.

I am loooking for a better way to get the info into the text box, without using description. If you have the time and the patience, could you please have a look for me.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
</head>
<body >

<td width="100%" rowspan="4"><FORM name="isc">
<table border="0" cellspacing="0" cellpadding="0">
<tr align="center">
<td nowrap height="11"> &nbsp;

<p>
<select name="example" size="1" onChange="redirect(this.options.selectedIndex)" style="width:200px">
<option selected>---Select1-------------</option>
<option>England</option>
<option>Wales</option>
</select>
</p>
<p>
<select name="stage2" size="1" onChange="redirect1(this.options.selectedIndex)" style="width:200px">
<option value=" " selected> </option>
<option value=" " selected>---Select2--------------</option>
<option value=" " selected>---Select2--------------</option>
</select>
</p>
<p>

<select name="stage3" size="1" onchange="displaydesc()" style="width:200px">
<option value=" " selected> </option>
<option value=" " selected>---Select3----------------</option>
<option value=" " selected>---Select3----------------</option>
</select>

<script>
<!--

/*
Triple Combo Script Credit
By Hamid Cheheltani/ JavaScript Kit (http://www.javascriptkit.com)
Visit http://javascriptkit.com for this and over 400+ other scripts
*/

var groups=document.isc.example.options.length
var group=new Array(groups)
for (i=0; i<groups; i++)
group[i]=new Array()

group[0][0]=new Option("---Select2---"," ");

group[1][0]=new Option("Now Select Region"," ");
group[1][1]=new Option("North East","47");
group[1][2]=new Option("North West","46");
group[1][3]=new Option("East Midlands","45");
group[1][4]=new Option("West Midlands","44");
group[1][5]=new Option("South East","43");
group[1][6]=new Option("South West","42");
group[1][7]=new Option("London","41");

group[2][0]=new Option("Now Select Region"," ");
group[2][1]=new Option("North Wales","115");
group[2][2]=new Option("Mid Wales","116");
group[2][3]=new Option("South East Wales","117");
group[2][4]=new Option("South Wales","118");
group[2][5]=new Option("South West Wales","119");

var temp=document.isc.stage2


function redirect(x){
for (m=temp.options.length-1;m>0;m--)
temp.options[m]=null
for (i=0;i<group[x].length;i++){
temp.options[i]=new Option(group[x][i].text,group[x][i].value)
}
temp.options[0].selected=true
redirect1(0)
}

var secondGroups=document.isc.stage2.options.length
var secondGroup=new Array(groups)
var descr=new Array(groups)
for (i=0; i<groups; i++) {
secondGroup[i]=new Array(group[i].length)
descr[i]=new Array(group[i].length)
for (j=0; j<group[i].length; j++) {
secondGroup[i][j]=new Array()
descr[i][j]=new Array()
}}

secondGroup[0][0][0]=new Option("---Select 3---"," ");
secondGroup[1][0][0]=new Option("---Select 3---"," ");
secondGroup[1][1][0]=new Option("Reason for Enquiry"," ");
secondGroup[1][1][1]=new Option("Advert","mailto:me@myadress.co.uk")
descr[1][1][1]= "My manager My training company my road mytown ";
secondGroup[1][1][2]=new Option("Apprenticeship Information","me@myadress.co.uk")
descr[1][1][2]= "Apprenticeship North East";
secondGroup[1][1][3]=new Option("Candidate Location"," ")
descr[1][1][3]= "Candidate Location North East";
secondGroup[1][1][4]=new Option("CSCS Cards"," ")
descr[1][1][4]= "CSCS Cards North East";
secondGroup[1][1][5]=new Option("Finance Department"," ")
descr[1][1][5]= "Finance Department North East";
secondGroup[1][1][6]=new Option("Funding"," ")
descr[1][1][6]= "Funding North East";
secondGroup[1][1][7]=new Option("Management"," ")
descr[1][1][7]= "Management North East";
secondGroup[1][1][8]=new Option("NVQ Assessment"," ")
descr[1][1][8]= "NVQ Assessment North East";

secondGroup[1][2][0]=new Option("Reason for Enquiry"," ");
secondGroup[1][2][1]=new Option("Advertising"," ");
secondGroup[1][2][2]=new Option("Apprenticeship Information"," ");
secondGroup[1][2][3]=new Option("Candidate Location"," ");
secondGroup[1][2][4]=new Option("CSCS Cards"," ");
secondGroup[1][2][5]=new Option("Finance Department"," ");
secondGroup[1][2][6]=new Option("Funding"," ");
secondGroup[1][2][7]=new Option("Management"," ");
secondGroup[1][2][8]=new Option("NVQ Assessment"," ");

secondGroup[1][3][0]=new Option("Reason for Enquiry"," ");
secondGroup[1][3][1]=new Option("Advertising"," ");
secondGroup[1][3][2]=new Option("Apprenticeship Information"," ");
secondGroup[1][3][3]=new Option("Candidate Location"," ");
secondGroup[1][3][4]=new Option("CSCS Cards"," ");
secondGroup[1][3][5]=new Option("Finance Department"," ");
secondGroup[1][3][6]=new Option("Funding"," ");
secondGroup[1][3][7]=new Option("Management"," ");
secondGroup[1][3][8]=new Option("NVQ Assessment"," ");

secondGroup[1][4][0]=new Option("Reason for Enquiry"," ");
secondGroup[1][4][1]=new Option("Advertising"," ");
secondGroup[1][4][2]=new Option("Apprenticeship Information"," ");
secondGroup[1][4][3]=new Option("Candidate Location"," ");
secondGroup[1][4][4]=new Option("CSCS Cards"," ");
secondGroup[1][4][5]=new Option("Finance Department"," ");
secondGroup[1][4][6]=new Option("Funding"," ");
secondGroup[1][4][7]=new Option("Management"," ");
secondGroup[1][4][8]=new Option("NVQ Assessment"," ");

secondGroup[1][5][0]=new Option("Reason for Enquiry"," ");
secondGroup[1][5][1]=new Option("Advertising"," ");
secondGroup[1][5][2]=new Option("Apprenticeship Information"," ");
secondGroup[1][5][3]=new Option("Candidate Location"," ");
secondGroup[1][5][4]=new Option("CSCS Cards"," ");
secondGroup[1][5][5]=new Option("Finance Department"," ");
secondGroup[1][5][6]=new Option("Funding"," ");
secondGroup[1][5][7]=new Option("Management"," ");
secondGroup[1][5][8]=new Option("NVQ Assessment"," ");

secondGroup[1][6][0]=new Option("Reason for Enquiry"," ");
secondGroup[1][6][1]=new Option("Advertising"," ");
secondGroup[1][6][2]=new Option("Apprenticeship Information"," ");
secondGroup[1][6][3]=new Option("Candidate Location"," ");
secondGroup[1][6][4]=new Option("CSCS Cards"," ");
secondGroup[1][6][5]=new Option("Finance Department"," ");
secondGroup[1][6][6]=new Option("Funding"," ");
secondGroup[1][6][7]=new Option("Management"," ");
secondGroup[1][6][8]=new Option("NVQ Assessment"," ");

secondGroup[1][7][0]=new Option("Reason for Enquiry"," ");
secondGroup[1][7][1]=new Option("Advertising"," ");
secondGroup[1][7][2]=new Option("Apprenticeship Information"," ");
secondGroup[1][7][3]=new Option("Candidate Location"," ");
secondGroup[1][7][4]=new Option("CSCS Cards"," ");
secondGroup[1][7][5]=new Option("Finance Department"," ");
secondGroup[1][7][6]=new Option("Funding"," ");
secondGroup[1][7][7]=new Option("Management"," ");
secondGroup[1][7][8]=new Option("NVQ Assessment"," ");

secondGroup[2][0][0]=new Option("---Select 3---"," ");
secondGroup[2][1][0]=new Option("Reason for Enquiry"," ");
secondGroup[2][1][1]=new Option("Advertising"," ");
secondGroup[2][1][2]=new Option("Apprenticeship Information"," ");
secondGroup[2][1][3]=new Option("Candidate Location"," ");
secondGroup[2][1][4]=new Option("CSCS Cards"," ");
secondGroup[2][1][5]=new Option("Finance Department"," ");
secondGroup[2][1][6]=new Option("Funding"," ");
secondGroup[2][1][7]=new Option("Management"," ");
secondGroup[2][1][8]=new Option("NVQ Assessment"," ");

secondGroup[2][2][0]=new Option("Reason for Enquiry"," ");
secondGroup[2][2][1]=new Option("Advertising"," ");
secondGroup[2][2][2]=new Option("Apprenticeship Information"," ");
secondGroup[2][2][3]=new Option("Candidate Location"," ");
secondGroup[2][2][4]=new Option("CSCS Cards"," ");
secondGroup[2][2][5]=new Option("Finance Department"," ");
secondGroup[2][2][6]=new Option("Funding"," ");
secondGroup[2][2][7]=new Option("Management"," ");
secondGroup[2][2][8]=new Option("NVQ Assessment"," ");

secondGroup[2][3][0]=new Option("Reason for Enquiry"," ");
secondGroup[2][3][1]=new Option("Advertising"," ");
secondGroup[2][3][2]=new Option("Apprenticeship Information"," ");
secondGroup[2][3][3]=new Option("Candidate Location"," ");
secondGroup[2][3][4]=new Option("CSCS Cards"," ");
secondGroup[2][3][5]=new Option("Finance Department"," ");
secondGroup[2][3][6]=new Option("Funding"," ");
secondGroup[2][3][7]=new Option("Management"," ");
secondGroup[2][3][8]=new Option("NVQ Assessment"," ");

secondGroup[2][4][0]=new Option("Reason for Enquiry"," ");
secondGroup[2][4][1]=new Option("Advertising"," ");
secondGroup[2][4][2]=new Option("Apprenticeship Information"," ");
secondGroup[2][4][3]=new Option("Candidate Location"," ");
secondGroup[2][4][4]=new Option("CSCS Cards"," ");
secondGroup[2][4][5]=new Option("Finance Department"," ");
secondGroup[2][4][6]=new Option("Funding"," ");
secondGroup[2][4][7]=new Option("Management"," ");
secondGroup[2][4][8]=new Option("NVQ Assessment"," ");

secondGroup[2][5][0]=new Option("Reason for Enquiry"," ");
secondGroup[2][5][1]=new Option("Advertising"," ");
secondGroup[2][5][2]=new Option("Apprenticeship Information"," ");
secondGroup[2][5][3]=new Option("Candidate Location"," ");
secondGroup[2][5][4]=new Option("CSCS Cards"," ");
secondGroup[2][5][5]=new Option("Finance Department"," ");
secondGroup[2][5][6]=new Option("Funding"," ");
secondGroup[2][5][7]=new Option("Management"," ");
secondGroup[2][5][8]=new Option("NVQ Assessment"," ");

var temp1=document.isc.stage3
function redirect1(y){
for (m=temp1.options.length-1;m>0;m--)
temp1.options[m]=null
for (i=0;i<secondGroup[document.isc.example.options.selectedIndex][y].length;i++){
temp1.options[i]=new Option(secondGroup[document.isc.example.options.selectedIndex][y][i].text,secondGroup[document.isc.example.options.selectedIndex][y][i].value)
}
temp1.options[0].selected=true
}

function go(){
location=temp1.options[temp.selectedIndex].value
}

function displaydesc(){
var desc=descr[document.isc.example.selectedIndex][document.isc.stage2.selectedIndex][document.isc.stage3.selectedIndex];
document.isc.txtdisplay.value=desc;
}

<!--displaydesc() -->
//-->
</script>
</p>
<p>
<textarea name="txtdisplay" style="width:250px; height:200px"></textarea>
</p>
<p>
<input type="button" name="test" value="Email This Person"
onClick="go()">
</p>
<p>&nbsp;</p></td>
</tr>
</table>
</FORM></td>

</body>
</html>

I have trimmed it down to only the relevent info.

Many thanks for your help so far.
Harveee
Harveee is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:50 AM.


Advertisement
Log in to turn off these ads.