Forum Moderators: open
Basically the jscript calls a php script which retreives information from a DB and returns the results to a html <div> tag with an id of txtState
<div id='txtState'>Results Here</div>
This woks fine, however I want the results to populate a dropdown box.
If I try the following.
<select id="txtState" name="state">Results Here</select>
It doesn't work.
Here is the jscript.
var xmlHttp
function showState(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="getstate.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 ¦¦ xmlHttp.readyState=="complete")
{
document.getElementById("txtState").innerHTML=xmlHttp.responseText
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
Can anybody help?
<select id="txtState" name="state">Results Here</select>
is invalid. A <select> can only have <option> elements as it's children. Start with this instead:
<select id="txtState" name="state"><option>Results Here</option></select>
Next, what does your responseText look like? Is it a text string that contains a bunch of <option> elements?