We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,571 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

automatic city display

I need javascript for automatic city display when i click one state from list box.

for example one list box i fetch karnataka, then automatically cities display whatever cities there in karnataka in another list box .

Please reply..am newbee of script writing....

3
Contributors
7
Replies
1 Day
Discussion Span
1 Year Ago
Last Updated
8
Views
siva28
Newbie Poster
22 posts since Oct 2011
Reputation Points: 8
Solved Threads: 0
Skill Endorsements: 0

I have a solution to this but it is intended for a form using select boxes... Is this what your looking for? And my solution is for counties and cities in England.

Metophase
Newbie Poster
16 posts since Nov 2011
Reputation Points: 23
Solved Threads: 0
Skill Endorsements: 0

Metophase..

Give that code...that is when i click england from select box then automatically loading cities are display into another select box...

please reply soon...

siva28
Newbie Poster
22 posts since Oct 2011
Reputation Points: 8
Solved Threads: 0
Skill Endorsements: 0
<form name="location">
<select name="country" id="country" onchange="redirect(this.options.selectedIndex)">
<option></option>
<option>England</option>
<option>Scotland</option>
<option>Wales</option>
<option>Northern Ireland</option>
</select>
<select name="city" id="city">
</select>
</form>
<script language="javascript">
							var countries =document.location.country.options.length
							var country = new Array(countries)
							for (i=0; i<countries; i++)
							country[i]=new Array()

							country[0][0] = new Option("")
							country[0][1] = new Option("Please select a Country First")

							country[1][0] = new Option("")
							country[1][1] = new Option("Manchester")
							country[1][2] = new Option("London")
							country[1][3] = new Option("Birmingham")

							country[2][0] = new Option("")
							country[2][1] = new Option("Aberdeen")
							country[2][2] = new Option("Glasgow")

							country[3][0] = new Option("")
							country[3][1] = new Option("flyglwnygfly")
							country[3][2] = new Option("glyndaflygllyl")
							country[3][3] = new Option("glyfaglynglyn")

							country[4][0] = new Option("")
							country[4][1] = new Option("Londonderry")
							country[4][2] = new Option("Dublin")
							country[4][3] = new Option("Galway and Mayo")

							var temp=document.location.city

							function redirect(x){
								for (m=temp.options.length-1;m>0;m--)
									temp.options[m]=null
								for (i=0;i<country[x].length;i++){
									temp.options[i]=new Option(country[x][i].text)
								}
								temp.options[0].selected=true
							}  
						</script>
Metophase
Newbie Poster
16 posts since Nov 2011
Reputation Points: 23
Solved Threads: 0
Skill Endorsements: 0

Erm maybe I should explain a bit more........ lol, you need to define all the cities associated with the country in the JavaScript... and have the countries listed in teh first select box... this can get very log winded for mine there are 47 counties and between 1-10 districts in each of the counties... but it does work very smoothly and if you add a couple more things you can cater for when a person as javascript turned off. this is the bare bones

Metophase
Newbie Poster
16 posts since Nov 2011
Reputation Points: 23
Solved Threads: 0
Skill Endorsements: 0

yeah, metophase sounds right. create the array and go from there.

super9876
Newbie Poster
8 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Thanks for sending code...
when i click england then display cities from englad... again when i click one of the cities from england automatically show whether deatils of that particular city.....
please reply

siva28
Newbie Poster
22 posts since Oct 2011
Reputation Points: 8
Solved Threads: 0
Skill Endorsements: 0

Siva, i would hate to think your are copying and pasting the code and not understanding it... before i give anything else away please think about each line of code.... there is more to learn from it than you think... just study it and see if you can understand exactly what is happening... if you do you can expand on it and learn from it... if you have a go and then send me the code i will help you further

Metophase
Newbie Poster
16 posts since Nov 2011
Reputation Points: 23
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.0824 seconds using 2.77MB