I am using an ajax call to update a select menu. The ajax call puts the list into my select menu by running from a different .php file.
Here is the JS insertion snippet:
if (req.status == 200) {
        document.getElementById('countydiv').innerHTML=req.responseText;
} else {
        alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
And here is the HTML:
    <label for="county">County:</label>
    <div id="countydiv">
        <select name="county">
            <option>Select State First</option>
        </select>
    </div>
Easy enough. The script works, but ONLY if the <div id="countydiv"> is in there.
How can I change the JavaScript to still work with markup that looks like this?
    <label for="county">County:</label>
    <select name="county">
    <option>Select State First</option>
    </select>
Update: Maybe I ought to include the whole function:
function getCounty(stateId) {
    var strURL="findCounty.php?state="+stateId;
    var req = getXMLHTTP();
    if (req) {
            req.onreadystatechange = function() {
                    if (req.readyState == 4) {
                            // only if "OK"
                            if (req.status == 200) {
                                    document.getElementById('countydiv').innerHTML=req.responseText;
                            } else {
                                    alert("There was a problem while using XMLHTTP:\n" + req.statusText);
                            }
                    }
            }
            req.open("GET", strURL, true);
            req.send(null);
    }
}
And the markup:
    <p>
        <label for="state">State:</label>
        <select name="state" onChange="getCounty(this.value)">
                <option>Select State...</option>
                <option>1</option>
                <option>2</option>
                <option>3</option>
        </select>
</p>
<p>
        <label for="county">County:</label>
        <select name="county">
                <option>Select State First</option>
        </select>
</p>
 
     
     
     
    