/    Sign up×
Community /Pin to ProfileBookmark

selected value of dropdown to display in textox

hiii all,

i have a two dropdown boxes one for country and one for city. when a particular country is selected city belonging to that country must be loaded in other dropdown and when a city is selected that particular city name must be displayed into textbox.
hope u understand it KOR.
plz help me

thankxxxxxxxxx ,
hope.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@KorJan 16.2008 — Could be something like this:
<i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;meta http-equiv="Content-Style-Type" content="text/css"&gt;
&lt;meta http-equiv="Content-Script-Type" content="text/javascript"&gt;
&lt;script type="text/javascript"&gt;
var ctr={
'-- Select a country --':['-- Select a city --'],
'France':['Paris','Marseille','Strassbourg'],
'Romania':['Bucuresti','Constanta','Timisoara','Suceava'],
'UK':['London','Manchester','Liverpool']
}
function setCountries(){
var parent=document.getElementsByName('countries')[0]
for(a in ctr){createEl(parent,a,a)}
}
function setCities(obj){
//initialize
obj.form['city'].value='';
var parent=obj.form['cities'];
while(parent.hasChildNodes()){
parent.removeChild(parent.childNodes[0])
}
if(obj.selectedIndex==0){return}
//first option
var o=document.createElement('option');
o.value='';
o.appendChild(document.createTextNode(ctr['-- Select a country --']));
parent.appendChild(o);
var c=obj.value;
//the other options
for(var i=0;i&lt;ctr[c].length;i++){createEl(parent,ctr[c][i],ctr[c][i])}
}
function createEl(parent,val,txt){
var o=document.createElement('option');
o.value=val;
o.appendChild(document.createTextNode(txt));
parent.appendChild(o);
}
onload=setCountries;
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form&gt;
&lt;select name="countries" onchange="this.length&gt;1?setCities(this):null"&gt;
&lt;/select&gt;
&lt;select name="cities" onchange="this.length&gt;1?city.value=this.value:null"&gt;
&lt;/select&gt;
&lt;br&gt;
&lt;input type="text" name="city"&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
×

Success!

Help @kuruvatti 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 6.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...