code to clear all select options

J

jason.tadeo

I am very new to java script and I am trying to be able to have two
select boxes. One that has states and one that has cities. On the
change or pick of the state then the cities in my data base are they
loaded. I do this using sajax (basically using java script to go back
to the server with out a page refresh). Well my problem comes after
that when I click on a state and then say I picked the wrong state and
clicked on another state in my cities select box sometimes has the
cities of the previous state. This happens because I have the options
loaded into the select box by java script but I was wonder if there was
a away I could totally clear out the select cites box before I add the
news cities. If I cant I guess I just am going to do a disable on the
select box.
 
R

RobG

I am very new to java script and I am trying to be able to have two
select boxes. One that has states and one that has cities. On the
change or pick of the state then the cities in my data base are they
loaded. I do this using sajax (basically using java script to go back
to the server with out a page refresh). Well my problem comes after
that when I click on a state and then say I picked the wrong state and
clicked on another state in my cities select box sometimes has the
cities of the previous state. This happens because I have the options
loaded into the select box by java script but I was wonder if there was
a away I could totally clear out the select cites box before I add the
news cities.

You can remove all the options by settting the select's length property
to zero (0). Note that a select element with no options is invalid, so
clear them out just before you put some back.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top