I have a page where the options in a select box are generated from the database. I'm trying to grab the selected value using Javascript, and I'm not quite sure why I'm having problems - as I understand it, the php/mySQL should run when the page first loads, and print the html output to the page - so it shouldn't be any different to a normal JS selectbox value.
It could be the JS I'm using, so here's the code for both - any suggestions would be great.
function copyValues()
{
var region = document.form.company_region.value;
var city = document.form.company_city.value;
var suburb = document.form.company_suburb.options[document.form.company_suburb.selectedIndex].value;
var street = document.form.company_street.value;
var address = region + city + suburb + street;
document.form.company_postal.value = address;
}
...
<tr>
<td width="262">Suburb</td>
<td width="194" colspan="2">
<?php
$query = "SELECT Suburb.Name FROM Suburb, City WHERE City.Name='Wellington' AND Suburb.CityID=City.CityID ORDER BY Suburb.Name ASC";
$result = mysql_query ($query,$db_link_id);
$total_num_rec=mysql_num_rows($result);
echo "<select size='1' name=\"company_suburb\">";
if($total_num_rec!=0){
for ($i=0; $i<$total_num_rec; $i++){
$current_row = mysql_fetch_array($result);
$suburb_name=$current_row[Name];
echo "<option>$suburb_name</option>";
}
}else{
$error_msg="No records found";
echo "<option>$error_msg</option>";
}
echo "</select>";
echo "</td>";
echo "</tr>";
?>
<?php
session_register("company_suburb");
?>
</td>
</tr>
...
Thanks!
Jen
