Hi,
I need to create a client-side script which will display a few lines of HTML (plain text will not be sufficient, it will need to have HTML codiing in it also) depending on the chosen option in a 3rd level select drop down list.
For example: <Choose from Select List 1> --> <Choice from dynamic select list 2> --> <choice from dynamic select list 3> --> <display some lines of HTML>
I've got the code which I've managed to get the first 3 dynamic lists sorted, but I'm having great difficulty in getting the chosen option in the 3rd list to display some HTML as a result. I'm pretty certain I need to use 'onchange= ' in the <select id="thirdChoice" tag.... but I'm not certain what to put...
I also know that the HTML for the 3rd level options need to go into an array like 'arrItems2[i]' and 'arrItemsGrp[i]' have. So for example, if I wanted to add some HTML lines after the client selects 'Oil Tanker' in the 3rd select list, I would somehow have to call the HTML which I would store in the arrItemsHTML[105] = "<b>some HTML here</b>" array.
Any ideas how I can pull this into either a <div> tag or something similar?!?! Like I said, I've found ways of doing this with plain text, e.g. pulling the data into a textbox, but as I'm sure you're aware, textboxes don't display HTML :(
Thanks in advance for any help you can offer, much appreciated.
Here's my code so far:
<script type="text/javascript">
<!--
var arrItems1 = new Array();
var arrItemsGrp1 = new Array();
arrItems1[3] = "Truck";
arrItemsGrp1[3] = 1;
arrItems1[4] = "Train";
arrItemsGrp1[4] = 1;
arrItems1[5] = "Car";
arrItemsGrp1[5] = 1;
arrItems1[6] = "Boat";
arrItemsGrp1[6] = 2;
arrItems1[7] = "Submarine";
arrItemsGrp1[7] = 2;
arrItems1[0] = "Planes";
arrItemsGrp1[0] = 3;
arrItems1[1] = "Ultralight";
arrItemsGrp1[1] = 3;
arrItems1[2] = "Glider";
arrItemsGrp1[2] = 3;
var arrItems2 = new Array();
var arrItemsGrp2 = new Array();
arrItems2[21] = "747";
arrItemsGrp2[21] = 0
arrItems2[22] = "Cessna";
arrItemsGrp2[22] = 0
arrItems2[31] = "Kolb Flyer";
arrItemsGrp2[31] = 1
arrItems2[34] = "Kitfox";
arrItemsGrp2[34] = 1
arrItems2[35] = "Schwietzer Glider";
arrItemsGrp2[35] = 2
arrItems2[99] = "Chevy Malibu";
arrItemsGrp2[99] = 5
arrItems2[100] = "Lincoln LS";
arrItemsGrp2[100] = 5
arrItems2[57] = "BMW Z3";
arrItemsGrp2[57] = 5
arrItems2[101] = "F-150";
arrItemsGrp2[101] = 3
arrItems2[102] = "Tahoe";
arrItemsGrp2[102] = 3
arrItems2[103] = "Freight Train";
arrItemsGrp2[103] = 4
arrItems2[104] = "Passenger Train";
arrItemsGrp2[104] = 4
arrItems2[105] = "Oil Tanker";
arrItemsGrp2[105] = 6
arrItems2[106] = "Fishing Boat";
arrItemsGrp2[106] = 6
arrItems2[200] = "Los Angelas Class";
arrItemsGrp2[200] = 7
arrItems2[201] = "Kilo Class";
arrItemsGrp2[201] = 7
arrItems2[203] = "Seawolf Class";
arrItemsGrp2[203] = 7
function selectChange(control, controlToPopulate, ItemArray, GroupArray) {
var myEle ;
var x ;
// Empty the second drop down box of any choices
for (var q=controlToPopulate.option
s.length;q
>=0;q--) controlToPopulate.options[
q]=null;
if (control.name == "firstChoice") {
// Empty the third drop down box of any choices
for (var q=form.thirdChoice.options
.length;q>
=0;q--) form.thirdChoice.options[q
] = null;
}
// ADD Default Choice - in case there are no values
myEle = document.createElement("op
tion") ;
myEle.value = 0 ;
myEle.text = "[SELECT]" ;
// controlToPopulate.add(myEl
e) ;
controlToPopulate.appendCh
ild(myEle)
// Now loop through the array of individual items
// Any containing the same child id are added to
// the second dropdown box
for ( x = 0 ; x < ItemArray.length ; x++ ) {
if ( GroupArray[x] == control.value ) {
myEle = document.createElement("op
tion") ;
//myEle.value = x ;
myEle.setAttribute('value'
,x);
// myEle.text = ItemArray[x] ;
var txt = document.createTextNode(It
emArray[x]
);
myEle.appendChild(txt)
// controlToPopulate.add(myEl
e) ;
controlToPopulate.appendCh
ild(myEle)
}
}
}
function selectChange(control, controlToPopulate, ItemArray, GroupArray) {
var myEle ;
var x ;
// Empty the second drop down box of any choices
for (var q=controlToPopulate.option
s.length;q
>=0;q--) controlToPopulate.options[
q]=null;
if (control.name == "firstChoice") {
// Empty the third drop down box of any choices
for (var q=form.thirdChoice.options
.length;q>
=0;q--) form.thirdChoice.options[q
] = null;
}
// ADD Default Choice - in case there are no values
myEle=document.createEleme
nt("option
");
theText=document.createTex
tNode("[SE
LECT]");
myEle.appendChild(theText)
;
myEle.setAttribute("value"
,"0");
controlToPopulate.appendCh
ild(myEle)
;
// Now loop through the array of individual items
// Any containing the same child id are added to
// the second dropdown box
for ( x = 0 ; x < ItemArray.length ; x++ ) {
if ( GroupArray[x] == control.value ) {
myEle = document.createElement("op
tion") ;
//myEle.value = x ;
myEle.setAttribute("value"
,x);
// myEle.text = ItemArray[x] ;
var txt = document.createTextNode(It
emArray[x]
);
myEle.appendChild(txt)
// controlToPopulate.add(myEl
e) ;
controlToPopulate.appendCh
ild(myEle)
}
}
}
// -->
</script>
<form name=form>
<table align="center">
<tr>
<td>
<select id="firstChoice" name="firstChoice" onchange="selectChange(thi
s, form.secondChoice, arrItems1, arrItemsGrp1);">
<option value="0" selected>[SELECT]</option>
<option value="1">Land</option>
<option value="2">Sea</option>
<option value="3">Air</option>
</select>
</td><td>
<select id="secondChoice" name="secondChoice" onchange="selectChange(thi
s, form.thirdChoice, arrItems2, arrItemsGrp2);">
</select>
<select id="thirdChoice" name="thirdChoice">
</select>
</td>
</tr>
</table>
</form>