so I've been working on this watching tutorials and such, but ran into a problem and need help. So i have a dropdown list that populates another dropdown list successfully. The problem is that I am creating the 2nd dropdown list to be populated, but want to populate an existing dropdownlist. Could anybody give me any advice on how to do this if I did not create the 2nd dropdown list and already had one(so it would populate the 2nd dropdown list which would already exist)?
Here is what I have:
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<form name="form1" action="submit.php" method='POST'>
<select name="country" onchange="window.getStates()">
<option value="">Select State</option>
<option value="louisiana">Louisiana</option>
<option value="texas">Texas</option>
<option value="alabama">Alabama</option>
<option value="mississippi">Mississippi</option>
</select>
<input type="submit" name="submit" value="Submit">
</form>
<script type="text/javascript">
function getStates()
{
var xmlhttp;
try{
xmlhttp = new XMLHttpRequest;
}catch(e)
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
if(xmlhttp)
{
var form = document['form1'];
var country = form['country'].value;
xmlhttp.open("GET", "getScools.php?country="+country, true);
xmlhttp.onreadystatechange = function ()
{
if(this.readyState == 4)
{
var s = document.createElement("select");
s.name= "state";
s.innerHTML = this.responseText;
if(form['state'])
{
form.replaceChild(s, form['state']);
}else
form.insertBefore(s, form['submit']);
}
}
xmlhttp.send(null)
}
}
</script>