Help - Search - Members - Calendar
Full Version: Dropdown list of countries in form element
HTMLHelp Forums > Web Authoring > Markup (HTML, XHTML, XML)
Forca
Hi

I'm busy with a registration page for my clients. I'm using the form element. How do I get the dropdown list of countries? I sure do not want to create one from scratch.

I'm looking for the <input> element that has this all pre-configured and I can just copy into my form element.

Thanks.
Christian J
This is usually done with a SELECT menu, not INPUT. There's no HTML element that does it automatically, but there are plenty of code examples written by others, e.g. http://www.textfixer.com/tutorials/country-dropdowns.php
pandy
Find a list of all countries. Use your editor's Find & Replace function to get them one on each row. Use it again to replace each line break with </option>[line break character]<option>. Then fix the very first and last tags.

Or view source at a site that uses such a dropdown and steal it.
pandy
Duh. Obviously I type too slow. blush.gif
Forca
I got the list easy enough. Thank you. But can one get the <select> tag embedded inside an <input> tag so that the select tag provides all the options for that particular input? Like here, I have an input of type = "text" and name = "country". I want the country field to be populated by means of the select tag. How can this be done?
pandy
No. You can't use a form control inside another. Why do you want the text input? You can achieve the look like this.

HTML
<select name="country">
<option selected disabled>Country</option>
<option>Sweden</option>
<option>France</option>
</select>
Forca
It works real good. Thanks pandy. I've learnt that the name attribute in the select or input tag is the key. The option value attribute gets assigned to the select name attribute.
pandy
Yes, the name of SELECT is paired with the value of the selected OPTION. OPTION can't have name. Or if there is no value as in my example above, the text content is used (Sweden, France). So often a value attribute isn't necessary.
Forca
QUOTE
OPTION can't have name. Or if there is no value as in my example above, the text content is used (Sweden, France). So often a value attribute isn't necessary.


I did not know that. Thanks.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2024 Invision Power Services, Inc.