Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reset drop down selection

Status
Not open for further replies.

SatishPutcha

Programmer
Joined
Mar 12, 2002
Messages
256
Location
IN
Hello All

I have a drop down box with cities. When a user selects a city I am showing a confirm box.

Now if the user selected OK then of course I keep the new selection in the drop down. But if the user selects "Cancel" I want to revert back to the earlier selection instead of the new one.

How do I accomplish this?

Please advise.

Regards
Satish

Thanks and Regards
Satish Kumar
 
You need a global variable to hold the current selectedIndex. Then you update this global variable once they select OK in the confirm box. If they select Cancel in the confirm box, then you can set the selectedIndex of the drop down to the value stored in the global variable.

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Easy. Have a variable which has the initial selection put in it on page load. Update this variable only when the user has selected "OK". If the select "Cancel", simply set the selectedIndex back to the value of the variable.

Hope this helps,
Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
That was quick!! Thanks guys.

Yes, I was wondering the same but since my confirm will be called in the onchange event of the drop down won't resetting the value fire the onchange event again?

Regards
Satish

Thanks and Regards
Satish Kumar
 
I just tested FF and IE in Windows and they both seem to allow you to set the selectedIndex without re-triggering the onchange. I expect the onchange will only fire if the <select> is changed (not the selectedIndex of it).

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Thanks Jeff. I will try it too.


Thanks and Regards
Satish Kumar
 
It would have been quicker to try it, than to post about it and wait for an answer ;-)

I really wonder sometimes why people don't try these things for themselves sometimes. Ah well!


Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Yes, you are right there. Should have tried it out first though I somehow assumed the onchange will fire when I try to reset the value.

I have tried it and its working with no problems!!!

Thanks and Regards
Satish Kumar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top