Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have an array which contains all countries of world
for example i have taken 3 countries.
JavaScript
var option_str = document.getElementById('country');
country_array[0]="USA|India|Australia";

var mySplitResult = country_array[0].split("|");

 for (var i = 0; i < mySplitResult.length; i++) {
	        option_str.options[i] = new Option(mySplitResult[i],mySplitResult[i]);
	    }

I have used split method to get each country

my prvios source was
HTML
<select name ="country" id = "country"></select>


after excute this query
out put is
HTML
<select name ="country" id = "country">
<option>USA</option>
<option>India</option>
<option>Australia</option>
</select>


But I want to do some thing like this:
HTML
<select name ="country" id = "country">
<option value="US">USA</option>
<option value="IN">India</option>
<option value="AU">Australia</option>
</select>


What is the code or where i can modify with my code which will see like the above
but u can use country code in array
Posted
Updated 8-Nov-11 19:12pm
v2
Comments
Sergey Alexandrovich Kryukov 9-Nov-11 1:09am    
This is not a question. Why doing it? And what did you try? What's the problem? Why wouldn't you put it right in first place?
--SA

1 solution

Try this
JavaScript
option_str.options[i] = new Option(mySplitResult[i],mySplitResult[i].substring(0,2).toUpperCase());
 
Share this answer
 
Comments
Surendra Tarai 9-Nov-11 3:23am    
No I do do not want like this
all country code may not first 2 character of country string.
Prerak Patel 9-Nov-11 3:38am    
Then you should have something else for country code, another array may be.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900