R
R
Rampage_Masta2011-10-22 06:37:45
JavaScript
Rampage_Masta, 2011-10-22 06:37:45

Select update?

There are 2 selects (country and city).
They work on the principle: a country is selected and filtered out by an sql query of the city for this country.
Because almost did not work with javascript, I want to ask how to implement through onchange, update select'a with cities.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
theRandom, 2011-10-22
@Rampage_Masta

Something like this using jQuery.

V
Veseloff, 2011-10-22
@Veseloff

Google the following topics:
• AJAX
• JSON
• appendChild
If jQuery is available, google:
• jQuery ajax
• jQuery append

E
egorinsk, 2011-10-24
@egorinsk

HTMLSelectElement (http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-94282980 ) has add()/remove() methods to clear the list of options and add options, while appendChild , if my memory serves me? works crookedly in different browsers.
Another option is to stupidly replace the select with a new select by replacing innerHTML on the wrapper - most likely it will work faster.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question