Country selection for a web form?
开发者_如何学编程How to create a HTML
dropdown with list of countries , is there any web services which i can use ? without entering manual.
You could use this jQuery plugin: JQuery Autocomplete Plugin extension for country list
Get an array of country names like this one.
Then use this in your file:
<select name="countries">
<?php
$countries = array(
'AF'=>'AFGHANISTAN',
'AL'=>'ALBANIA',
'DZ'=>'ALGERIA',
'AS'=>'AMERICAN SAMOA',
...rest of data from site link above
);
foreach($countries as $key => $array) {
?><option value="<?=$key?>"><?=$value?></option>
}
</select>
?>
Explanation:
Creates a array of country names, then goes through one at a time and writes each country name into an <option>
within your <select></select>
tags.
精彩评论