By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,228 Members | 1,374 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,228 IT Pros & Developers. It's quick & easy.

How can I load the options for an HTML Select element from a file?

P: n/a
I am working with an HTML-based form that uses a select element that
requires about 200 options. Is there a way that I can load, or select
one of these options from a file, rather than hardcode them into the
select element?

Thanks
Jul 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
jo******@comcast.net (John C) wrote:
I am working with an HTML-based form that uses a select element that
requires about 200 options. Is there a way that I can load, or select
one of these options from a file, rather than hardcode them into the
select element?


What sort of file? Where is the file? What languages are supported on
your server? How often does the list of 200 options change?

Anyway, there's no way of doing this in HTML. It can be done server
side (with ASP or PHP or SSI, etc.) or less reliably client side (with
JavaScript).

Of course, a list of 200 options is quite difficult for the user to
use and the best solution might be to avoid it altogether.

Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <st***@pugh.net> <http://steve.pugh.net/>
Jul 20 '05 #2

P: n/a
Steve Pugh <st***@pugh.net> wrote:
jo******@comcast.net (John C) wrote:
I am working with an HTML-based form that uses a select element that
requires about 200 options. Is there a way that I can load, or select
one of these options from a file, rather than hardcode them into the
select element?


What sort of file? Where is the file? What languages are supported on
your server? How often does the list of 200 options change?

Anyway, there's no way of doing this in HTML. It can be done server
side (with ASP or PHP or SSI, etc.) or less reliably client side (with
JavaScript).

Of course, a list of 200 options is quite difficult for the user to
use and the best solution might be to avoid it altogether.


What would be an easier way to let the user enter, for example, his
country on a form where he is filling out his mailing address,
assuming that "countryID" is a foreign key in the Addresses table?

--
Harlan Messinger
Remove the first dot from my e-mail address.
Veuillez ôter le premier point de mon adresse de courriel.
Jul 20 '05 #3

P: n/a
Harlan Messinger <hm*******************@comcast.net> wrote:
Steve Pugh <st***@pugh.net> wrote:
Of course, a list of 200 options is quite difficult for the user to
use and the best solution might be to avoid it altogether.
What would be an easier way to let the user enter, for example, his
country on a form where he is filling out his mailing address,


If the country is only ever going to be printed out on mailing labels
then a plain text field will suffice. It doesn't matter if some people
put UK, others put United Kingdom, and others England, the mail will
still get there. Typing the country will usually be quicker than
finding it in a drop down (unless you happen to live in the Federated
States of Micronesia).

If the country is needed by some server side application (e.g.to
calculate shipping costs) then a select element is the best option.
But a list of countries is a fairly atypical case - everyone knows
what country they live, and sorting the countries alphabetically is
pretty much the norm (take a list of countries and randomise the
order, or even just sort them by contintent, and see how much longer
it takes you to find your country).

But if the data is less familiar then a select element may not be the
best choice. For example, text inside select elements isn't found by
browsers' search facilities so it can be harder to find the option
you're looking for.
assuming that "countryID" is a foreign key in the Addresses table?


I can only guess as to what this means. It's not HTML is it?

Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <st***@pugh.net> <http://steve.pugh.net/>
Jul 20 '05 #4

P: n/a
On Thu, 1 Apr 2004, Steve Pugh wrote:
If the country is needed by some server side application (e.g.to
calculate shipping costs) then a select element is the best option.


For sure, a select list with hundreds of entries is a most unsuitable
thing to present to any user, if it can possibly be avoided.

Better, could be to let them type it in for themselves, and do a
preliminary submission of the form; then on the server side, if you
don't get an exact match with what you expected, you can look-up your
own list of countries (using some kind of fuzzy match algorithm) to
find some normalised names which seem to match, and feed the form back
to them, with the accepted parameters already filled-in, and with a
pull-down containing your (manageable number of) suggestions for the
missing field(s). However, this isn't really a topic for the HTML
group, since it involves server-side processing.
Jul 20 '05 #5

P: n/a
On Thu, 01 Apr 2004 13:15:07 +0100, Steve Pugh <st***@pugh.net> wrote:
jo******@comcast.net (John C) wrote:
I am working with an HTML-based form that uses a select element that
requires about 200 options. Is there a way that I can load, or select
one of these options from a file, rather than hardcode them into the
select element?


What sort of file? Where is the file? What languages are supported on
your server? How often does the list of 200 options change?

Anyway, there's no way of doing this in HTML. It can be done server
side (with ASP or PHP or SSI, etc.) or less reliably client side (with
JavaScript).

Of course, a list of 200 options is quite difficult for the user to
use and the best solution might be to avoid it altogether.

Steve


Another option is to have the user enter the first letter, and have that
lead to a select dropdown with only those countries. Again, this is
complicated.

Better still, have a separate page linked which lists all the (perhaps
2-letter) country codes and allow the user to look it up and enter that
code in a text box. Confirmation page can list the 2-letter code entered
along with the country name that matches to ensure no error in entering or
referencing was made.
Jul 20 '05 #6

P: n/a

"Steve Pugh" <st***@pugh.net> wrote in message
news:59********************************@4ax.com...
Harlan Messinger <hm*******************@comcast.net> wrote:
Steve Pugh <st***@pugh.net> wrote:
Of course, a list of 200 options is quite difficult for the user to
use and the best solution might be to avoid it altogether.
What would be an easier way to let the user enter, for example, his
country on a form where he is filling out his mailing address,


If the country is only ever going to be printed out on mailing labels
then a plain text field will suffice. It doesn't matter if some people
put UK, others put United Kingdom, and others England, the mail will
still get there. Typing the country will usually be quicker than
finding it in a drop down (unless you happen to live in the Federated
States of Micronesia).


Granted--almost. Even ignoring the possibility that someone might type in
nonsense (which I'll overlook because that's true for any free-form text
field), someone could type in a genuine country name but in a foreign
language that the post office may not recognize.

If the country is needed by some server side application (e.g.to
calculate shipping costs) then a select element is the best option.
But a list of countries is a fairly atypical case - everyone knows
what country they live, and sorting the countries alphabetically is
pretty much the norm (take a list of countries and randomise the
order, or even just sort them by contintent, and see how much longer
it takes you to find your country).

But if the data is less familiar then a select element may not be the
best choice. For example, text inside select elements isn't found by
browsers' search facilities so it can be harder to find the option
you're looking for.


Right. It's just that you didn't mention this caveat, and there are
certainly many 200-item lists one could have in which the items are in some
kind of intuitive order.
Jul 20 '05 #7

P: n/a
jo******@comcast.net (John C) wrote in message news:<3b**************************@posting.google. com>...
I am working with an HTML-based form that uses a select element that
requires about 200 options. Is there a way that I can load, or select
one of these options from a file, rather than hardcode them into the
select element?

Thanks


Thanks to everyone who responded to this message, you have supplied
me with some good questions and technical approaches. I am working in
PHP and HTML and have access to a MySQL db. From a logic
point-of-view, here is what I came up with last night:

- user accesses page with form
- user requests access to the 200 records
- begin loop:
- sql query gets one record
- PHP writes <option>record info</option>
- end loop
- results displayed as select list, possibly in a pop-up window
- user makes selection
- selection returned with form information to PHP processing

Any further comments/suggestions are greatly appreciated.
Jul 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.