/    Sign up×
Community /Pin to ProfileBookmark

I am trying to code a dropdown list which its basic functions are to load data from an XML file ( which i allready did ) and as soon the user select an option, another dropdown is displayed.

what i want to do is a country drop down, which when a country is selected, then its towns are displayed in another country.

any simple help?

thanks.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@mark-mltauthorAug 07.2008 — pls help me :S im not good in jScript ?
Copy linkTweet thisAlerts:
@KorAug 07.2008 — Here's a not so old example written by me for somebody else, maybe it will help:
<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 myval = [];
//India
myval['India']=['Bombay','Calcutta','Hyderabad','Jaipur','New Delhi'];
//Pakistan
myval['Pakistan']=['Faisalabad','Islamabad','Karachi','Lahore'];
// and so on...
function newOpt(v){//main function
var root = document.getElementById('cities');
removeEl(root);//removes the old childNodes
for(var i=0;i&lt;myval[v].length;i++){
var opt = createEl('option');//creates option element
var txt = document.createTextNode(myval[v][i])//creates textNode
opt.appendChild(txt);//appends textNode
createAt(opt,'value',myval[v][i])//sets the attribute
root.appendChild(opt)//appends the element
}
}
function removeEl(obj){
while(obj.hasChildNodes()){
obj.removeChild(obj.childNodes[0])
}
}
function createEl(el){
this.obj=document.createElement(el);
return this.obj;
}
function createAt(obj,att,val){
obj.setAttribute(att,val);
return
}
function valid(){
var obj=document.getElementById('countries');
if(obj.selectedIndex==0){
alert('Please, select a country!');
return false
}
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form action="" onsubmit="return valid()"&gt;
&lt;select name="countries" id="countries" onchange="if(this.selectedIndex&gt;0){newOpt(this.value)}else{removeEl(document.getElementById('cities'))}"&gt;
&lt;option value=""&gt;-- Select a country -- &lt;/option&gt;
&lt;option value="India"&gt;India&lt;/option&gt;
&lt;option value="Pakistan"&gt;Pakistan&lt;/option&gt;
&lt;/select&gt;

&lt;select name="cities" id="cities"&gt;
&lt;/select&gt;
&lt;br&gt;
&lt;br&gt;
&lt;input type="submit" id="Sub" value="Submit"&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@mark-mltauthorAug 10.2008 — great help mate !!! now im trying to get rss feed for the last selection.
Copy linkTweet thisAlerts:
@mark-mltauthorAug 10.2008 — one more question.

i want to fill the dropdowns from an xml file ... how can i do that?

i still didnt managed ?
×

Success!

Help @mark-mlt 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.17,
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,
)...