PDA

View Full Version : js Help with drop down menus



crazy8
02-14-2007, 07:28 PM
Ok I have some code I have writen so far and I am a total n00b with js so examples would be nice to see. Anyway what I need to do is for a client of mine. His site has many pages and many forms on some of the pages. His site can be seen here http://www.millermachinecompany.com/4mx07/main.htm on my testing server. Ok so here is what I need to do with the code I have now.
1) A single js file that will work for the whole site.
2) Will work with having multiple forms on pages.
3) Will populate all drop downs when page loads

I think thats it. Atleast for now. But here is what I have for code. It works for the first drop down on the page but thats it. So Im not sure what edits I have to make to the code to get it what I need to do.

var Cobra = new Array();
Cobra[0] = "Cobra King 50";
Cobra[1] = "CM50";

var Honda = new Array();
Honda[0] = "CR80";
Honda[1] = "CR85";
Honda[2] = "CR125";
Honda[3] = "CR250";
Honda[4] = "CR500";
Honda[5] = "CRF50";
Honda[6] = "CRF150";
Honda[7] = "CRF250";
Honda[8] = "CRF450";

var KTM = new Array();
KTM[0] = 'KTM50';
KTM[1] = 'KTM65';
KTM[2] = 'KTM85';
KTM[3] = 'KTM125';
KTM[4] = 'KTM250';
KTM[5] = 'KTM450';

var Kawasaki = new Array();
Kawasaki[0] = 'KLX110';
Kawasaki[1] = 'KX60';
Kawasaki[2] = 'KX65';
Kawasaki[3] = 'KX80';
Kawasaki[4] = 'KX85';
Kawasaki[5] = 'KX125';
Kawasaki[6] = 'KX250';
Kawasaki[7] = 'KXF250';
Kawasaki[8] = 'KXF450';


var Suzuki = new Array();
Suzuki[0] = 'DZ110';
Suzuki[1] = 'DRZ250';
Suzuki[2] = 'DRZ400';
Suzuki[3] = 'RM85';
Suzuki[4] = 'RM125';
Suzuki[5] = 'RM250';
Suzuki[6] = 'RMZ250';
Suzuki[7] = 'RMZ450';

var Yamaha = new Array();
Yamaha[0] = 'TTR50';
Yamaha[1] = 'TTR90';
Yamaha[2] = 'TTR125';
Yamaha[3] = 'YZ80';
Yamaha[4] = 'YZ85';
Yamaha[5] = 'YZ125';
Yamaha[6] = 'YZ250';
Yamaha[7] = 'YZF250';
Yamaha[8] = 'YZF450';

function populateDropdown(arry)
{

for (var i = 0; i < arry.length; i++)
{
document.myForm.os2.options[i] = new Option(arry[i], arry[i]);
}
}

function updateDropdown()
{
var modelArray
var selectedos0;
var os0Dropdown = document.myForm.os0;

for (var i = 0; i < os0Dropdown.options.length; i++)
{
if (os0Dropdown.options[i].selected)
{
selectedos0 = os0Dropdown.options[i].value;
}
}

if (selectedos0 == 1)
{
modelArray = Cobra;
populateDropdown(modelArray);
}

if (selectedos0 == 2)
{
modelArray = Honda;
populateDropdown(modelArray);
}

if (selectedos0 == 3)
{
modelArray = KTM;
populateDropdown(modelArray);
}

if (selectedos0 == 4)
{
modelArray = Kawasaki;
populateDropdown(modelArray);
}

if (selectedos0 == 5)
{
modelArray = Suzuki;
populateDropdown(modelArray);
}

if (selectedos0 == 6)
{
modelArray = Yamaha;

populateDropdown(modelArray);
}
}

Thank you in advance for the help.