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" xml:lang="en" lang="en">
<head>
<title></title>
<script type="text/javascript">
/*<![CDATA[*/
var cars=[
['audi',['audi model1',300],['audi model2',400]],
['volvo',['volvo model1',500],['volvo model2',600]]
];
function SelectInit(ary,s1,s2,p){
s1=document.getElementById(s1);
s2=document.getElementById(s2);
p=document.getElementById(p);
for (var z0=0;z0<ary.length;z0++){
s1.options[s1.options.length]=new Option(ary[z0][0],z0);
}
s1.selectedIndex=0;
var nu=s2.options.length
s1.onchange=function(){ Select(this,ary,s1,s2,p,nu); }
s2.onchange=function(){ Select(this,ary,s1,s2,p,nu); }
}
function Select(sel,ary,s1,s2,p,nu){
p.value='';
if (sel==s1){
s2.options.length=nu;
if (ary[s1.value]){
for (var z0=1;z0<ary[s1.value].length;z0++){
s2.options[s2.options.length]=new Option(ary[s1.value][z0][0],ary[s1.value][z0][1]);
}
}
s2.selectedIndex=0;
}
else if (sel==s2&&s2.value!='X'){
p.value=s2.value;
}
}
</script>
</head>
<body>
<select id="S1" >
<option value="X" >Cars</option>
</select>
<select id="S2" >
<option value="X">Models</option>
</select>
<input id="Price" />
<script type="text/javascript">
/*<![CDATA[*/
SelectInit(cars,'S1','S2','Price');
/*]]>*/
</script>
</body>
</html>
Bookmarks