/    Sign up×
Community /Pin to ProfileBookmark

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. Is there anyway to do this without using javascript? All of the cities/states are stored in a database. A tutorial would be greatly appreciated. Thanks for any help.
-Cody

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJun 14.2005 — If you want the cities to populate without submitting the page to do the processing, then you'll have to use some sort of client-side technology, whether it be Javascript, Java applet, Flash, etc.
Copy linkTweet thisAlerts:
@FirEwAteRauthorJun 14.2005 — 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);
}
} [/CODE]


But make the where clause dyncamically select using the id parsed from the country option input.
×

Success!

Help @FirEwAteR spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...