I am working on creating a 2 Level Interdependent Select List and I am using javascriptkit.com’s code they provided.
[code=html]
<form name=”classic”>
<select name=”styles” size=”1″ onChange=”updatecolors(this.selectedIndex)” style=”width: 150px”>
<option selected>Select A City</option>
<option value=”usa”>USA</option>
<option value=”canada”>Canada</option>
<option value=”uk”>United Kingdom</option>
</select>
<select name=”colors” size=”1″ style=”width: 150px”>
</select>
</form>
<script type=”text/javascript”>
var styleslist=document.classic.styles
var colorslist=document.classic.colors
var colors=new Array()
colors[0]=””
colors[1]=[“New York|newyorkvalue”, “Los Angeles|loangelesvalue”, “Chicago|chicagovalue”, “Houston|houstonvalue”, “Austin|austinvalue”]
colors[2]=[“Vancouver|vancouvervalue”, “Tonronto|torontovalue”, “Montreal|montrealvalue”, “Calgary|calgaryvalue”]
colors[3]=[“London|londonvalue”, “Glasgow|glasgowsvalue”, “Manchester|manchestervalue”, “Edinburgh|edinburghvalue”, “Birmingham|birminghamvalue”]
function updatecolors(selectedcolorsgroup){
colorslist.options.length=0
if (selectedcolorsgroup>0){
for (i=0; i<colors[selectedcolorsgroup].length; i++)
colorslist.options[colorslist.options.length]=new Option(colors[selectedcolorsgroup][i].split(“|”)[0], colors[selectedcolorsgroup][i].split(“|”)[1])
}
}
</script>
Which is working to they way they said it would. I am trying to make a modification to it to which I have on idea where to start as i know very little javascript.
Basically what I want to do is delete the <option selected>Select A City</option> from the first select field and make it where when you first see the field it displays the USA option.
Since the USA option will be the on that is showing when you enter the page I don’t want second select field to be blank but instead show the cities of the USA. Then if they choose to select on Canada it would delete the USA cities and just show the canadian cities like it is already doing.
Anyone know how I can achieve this?
Thanks so much for all your help!