PDA

View Full Version : Drop down lists


daved83
07-13-2009, 02:15 PM
Hi,

I'm trying to gnerate dropdown options using javascript and php, I have a php script that works fine on its own. When I try to execute the file with the onchange event however, nothing happens.I have an external .js file which tries to achieve this. Here's a copy of some of my code

<form action="process.php" method="post">
<table>
<td align="right">Language of interest:</td>
<td>
<select name="language" onchange="getCity('findcity.php?language='+this.value)">
<option value="none selected"> --- select --- </option>
<option value="French">French</option>
<option value="German">German</option>
<option value="Italian">Italian</option>
<option value="Spanish">Spanish</option>
<option value="Russian">Russian</option>
<tr>
<td align="right">Course Type</td>
<td>
<select name="course" >
<option value="none selected"> --- select --- </option>
<option value="Junior">Junior</option>
<option value="Other">Other</option>
</tr>
<tr>
<td align="right">School</td>
<td>
<select name="school">
<div id="citydiv">
<option>Select School</option>
</select>
</div>
</td>
</tr>



getCity.js



function getCity(strURL)
{
var req = getXMLHTTP(); // fuction to post xmlhttp object
if (req)
{
req.onreadystatechange = function()
{
if (req.readyState == 4) { //data is retrieved from server
if (req.status == 200) { // which reprents ok status
document.getElementById('citydiv').innerHTML=req.responseText;
}
else
{
alert("There was a problem while using XMLHTTP:\n");
}
}
}
req.open("get", strURL, true); //open url using get method
req.send(null);
}
}

Any help would be great as I'm brand new to this

Cheers