If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

Getting Drop downs to "reset"

I am using Javascript so that when someone selects their state in a drop-down another one appears where they can select their city. Then once they do that information appears about sales reps in their area. This is working great except that if someone selects a state and city then decides to pick a different state the old information stays and nothing happens. I hope I'm explaining this clearly, but if I select the state and the second drop down appears and I change the state without selecting a city it "resets" like I want it to but not if I've already selected a city. does that make sense? So I'm not sure how to make it work. This is the code I have:

But the answer to your question is when a state is selected from your dropdown (onchange) reset the selectedIndex of the city dropdown to 0. That forces the user to select a state before a city.

I'm not sure how to do that... The only reason I have so much code is because it was the only way I could figure out to do it! I'm certainly open to suggestions but despite the fact that each thing is set to display:none if I don't tell it to be display none again in each script it shows up anyway! How do I do what you are describing?

I already posted a link to a page showing all the code necessary to do this in my first reply. If you had looked at that page then you would see how to get rid of the unnecessary repetitive code.

And I've often used that kind of approach, myself. But in this case, since we *also* had to decide whether or not to even show the second <select>, I opted for a more simplistic approach. In total, it's roughly the same amount of code, just more HTML and less JS than the mostly-in-JS method.

I did look at your link but seeing as my Javascript knowledge is 0 (which is self-evident) I did not know how to make that work for my situation specifically. Nonetheless, I appreciate your response.

Apart from defining the entries you wanted in the second list for each selection from the first in the array at the top of the script, the only other thing that would need changing in the script I posted to get exactly what you want would be to add two extra lines to show and hide the second dropdown. Getting everything to work apart from hiding the second select wouldn't even require a knowledge of JavaScript as it is fairly obvious by looking at both the script and the working example as to what value go where in the array to have them display just by trying out the example.

If you want to use dynamic effects in your web page then you really ought to learn JavaScript as that is what all such effects are written using. Only if you are going to use effects where someone has already written the entire script for you can you avoid needing to know JavaScript in order to add effects to your page.

Trying to add effects to your web page without first learning JavaScript is like trying to fly a plane without taking any flying lessons.