Forca
Feb 10 2017, 12:38 AM
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
Feb 10 2017, 07:22 AM
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
Feb 10 2017, 07:27 AM
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
Feb 10 2017, 07:29 AM
Duh. Obviously I type too slow.
Forca
Feb 15 2017, 11:49 PM
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
Feb 16 2017, 12:50 AM
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
Feb 16 2017, 08:29 PM
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
Feb 16 2017, 11:36 PM
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
Feb 17 2017, 02:58 PM
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.