PDA

View Full Version : Double Combo Boxes



smeshy123
Jul 21st, 2005, 04:09 AM
What is the easiest way to create double combo boxes in JavaScript...what I am trying to do is load a bunch of information in a database and have 2 drop down menus. The information in the 2nd dropdown menu is conditional on what is in the first dropdown menu.

My first menu will have years coming from a database, my 2nd menu will have the months that are in each year, but will only show up when the proper year is selected all loaded from a database.

Any ideas?

Thanks!

Smesh

medigerati
Jul 21st, 2005, 05:39 AM
Maybe this may help:

<html>
<head>
<script type="text/javascript">
<!--
// Months information
var months = new Array();
for(var i = 0; i<12; i+=1){
months['1990'] = new Array('Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', 'August', 'Sep', 'Oct', 'Nov', 'Dec');
months['1991'] = new Array('Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', 'August', 'Sep', 'Oct', 'Nov', 'Dec');
months['1992'] = new Array('Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', 'August', 'Sep', 'Oct', 'Nov', 'Dec');
months['1993'] = new Array('Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', 'August', 'Sep', 'Oct', 'Nov', 'Dec');
}

function getMonths(){
var year = document.formName.elements['year'].value;
for(var eye = 0; eye<12; eye+=1){
document.formName.elements['month'].options[eye] = new Option(months[year][eye]);
}
}

-->
</script>
</head>
<body>
<form name="formName">
<select name="year" onchange="getMonths();">
<option value="1990">1990</option>
<option value="1991">1991</option>
<option value="1992">1992</option>
<option value="1993">1993</option>
</select>
<select name="month">
</select>
</form>
</body>
</html>

Hope it's what you needed,
Kevin

smeshy123
Jul 21st, 2005, 05:54 AM
That is exackly what I needed! Well...sort of...the months are being taken out of a database...but it's close enough! Thanks!

Smesh