PDA

View Full Version : text link to drop down


sandalwood
12-26-2002, 09:45 PM
I found this great code that does exactly what I need it to do, only it fills a dropdown menu with results based on a text link, and I would like to use a nother dropdown. Can someone help me with this, please?

Here is the script for the form:

<form name="dynmenu_form">
<a href="java script:void(null);" onClick="FillList(0);return false">Ford</a><br />
<a href="java script:void(null);" onClick="FillList(1);return false">Toyota</a><br /><br />
<select name="models" style="width: 160px" onChange="if (this.selectedIndex != 0) {alert(this.options[selectedIndex].value);}">
<option></option>
</select>
</form>

Adam20002
12-26-2002, 10:28 PM
Can we see the code inside the FillList function ?

Adam :)

sandalwood
12-27-2002, 02:30 PM
Adam, here is the fill script:

<script language="JavaScript">
<!--

var cat = new Array;

//Create the arrays here, you can add as much as you like.

newCat(3); //Dodge - the number stands for the number of models.
Opt("Tempo", "autos/Dodge_gr_caravan_ES.jpg");
Opt("Tauras", "autos/Dodge_gr_caravan_ES.jpg");
Opt("Windstar", "autos/Dodge_gr_caravan_ES.jpg");

newCat(4); //Toyota
Opt("Tercel", "http://www.toyota.com/tercel.html");
Opt("Corolla", "http://www.toyota.com/tauras.html");
Opt("Camry", "http://www.toyota.com/camry.html");
Opt("Avalon", "http://www.toyota.com/avalon.html");

//End

var catsIndex = -1;
var itemsIndex;

function newCat(i) {
catsIndex++;
cat[catsIndex] = new Array(i);
itemsIndex = 0;
}

function Opt(txt,url) {
cat[catsIndex][itemsIndex] = new myOptions(txt,url);
itemsIndex++;
}

function myOptions(text,value){
this.text = text;
this.value = value;
}

newCat(3); //Dodge - the number stands for the number of models.
Opt("Dodge Grand Caravan ES", "autos/Dodge_gr_caravan_ES.jpg");
Opt("Tauras", "autos/Dodge_gr_caravan_ES.jpg");
Opt("Windstar", "autos/Dodge_gr_caravan_ES.jpg");

newCat(4); //Toyota
Opt("Tercel");
Opt("Corolla");
Opt("Camry");
Opt("Avalon");

function FillList(intIndex) {

document.dynmenu_form.picture.length = 1; //clear list, leave one blank
for (i = 0; i < cat[intIndex].length; i++) {
document.dynmenu_form.picture.options[(i+1)] = new Option(cat[intIndex][i].text, cat[intIndex][i].value);
}
document.dynmenu_form.picture.selectedIndex = 0;
document.dynmenu_form.picture.focus() ;

}
//-->
</script>