
June 14th, 2005, 04:19 PM
|
|
Junior Member
|
|
Join Date: Jun 2005
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
dynamically loading cities.
Hi, I'm looking to make a page that dynamically loads cities into an option field according to the country/state selected on the same page. All of the cities/states are stored in a mySQL database.
I would like to be able to use something like this:
Code:
function loadState(id) {
var s;
var stateName;
var cstate = new Array();
if(id==2){
<? //get states list from database
$sqlState="select * from ae_states where country_id=2 order by state_name ASC";
$reState=mysql_query($sqlState);
$sct = mysql_num_rows($reState);
$k=0;
while($rowState = mysql_fetch_array($reState)) { ?>
s=<?=$k?>;
stateName='<? echo $rowState["state_name"]; ?>';
cstate[s]=stateName;
<? $k=$k+1;
} ?>
var len = cstate.length;
cstate[len]="All states";
var field2 = document.frm_advSearch.asrch_state;
for(j=0; j<len+1; j++){
newOpt=cstate[j];
field2.length=j+1;
field2.options[j]= new Option(newOpt,newOpt);
}
}
But make the where clause dyncamically select using the id parsed from the country option input.
|