Forum Moderators: coopster
Pick a Phone
<form name="classic">
<select name="countries" onChange="updatecities(this.selectedIndex)" style="width: 150px">
<option selected>Select A Brand</option>
<?php
//start brand
db connection here
$sqlbrand ="SELECT Manufacturer FROM manufacturer ORDER by Manufacturer ASC";
$sqlbrand_result = mysql_query($sqlbrand,$connection) or die ( "Couldn't execute your query");
while ($row = mysql_fetch_array($sqlbrand_result)) {
$brand = $row["Manufacturer"];
echo"<option value='$brand'>$brand</option>";
}
?>
</select>
<select name="cities" style="width: 150px" onClick="alert(this.options[this.options.selectedIndex].value)">
</select>
</form>
<script type="text/javascript">
var countrieslist=document.classic.countries
var citieslist=document.classic.cities
var cities=new Array()
cities[0]=""
<?php
$sqlbrand ="SELECT Manufacturer FROM manufacturer ORDER by Manufacturer ASC";
$sqlbrand_result = mysql_query($sqlbrand,$connection) or die ( "Couldn't execute your queryphones");
$z=1;
while ($row = mysql_fetch_array($sqlbrand_result)) {
$brand = $row["Manufacturer"];
$sql2 = "SELECT id,Phone,Model FROM phone WHERE Manufacturer LIKE '%$brand%' ORDER by announced DESC";
$sql_result2= mysql_query($sql2,$connection) or die ( "Couldn't execute your query.");
while ($row = mysql_fetch_array($sql_result2)) {
$id = $row["id"];
$Phone = $row["Phone"];
$Model = $row["Model"];
echo"cities[$z]=\"$Model¦$Phone\"";
}
$z++;
};
?>
function updatecities(selectedcitygroup){
citieslist.options.length=0
if (selectedcitygroup>0){
for (i=0; i<cities[selectedcitygroup].length; i++)
citieslist.options[citieslist.options.length]=new Option(cities[selectedcitygroup][i].split("¦")[0], cities[selectedcitygroup][i].split("¦")[1])
}
}
</script>
[edited by: coopster at 4:39 pm (utc) on June 8, 2005]
[edit reason] no urls per TOS [webmasterworld.com] [/edit]