Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I am a beginner in jQuery.
I working on code, where I have to clear all the text fields' and dropdownlists' value once an anchor is clicked which toggles a div (say A).

So when A is showing, all the textboxes and dropdownlist selected value should be cleared.

I googled it, but couldn't find a concrete solution.
Kindly help me with it.

Thanks in Advance,

Amit Pandey.
Posted
Comments
Thanks7872 27-Jan-16 3:12am    
http://stackoverflow.com/questions/18479475/jquery-clear-textboxes-and-reset-to-default-drop-down-menu-values
AmitKPandey28 27-Jan-16 3:28am    
Thank you for the link :)
Sergey Alexandrovich Kryukov 27-Jan-16 3:20am    
You could not find it, because nobody would bother publishing "concrete solutions", because they are not efficient, carry too little knowledge. People try to publish universal solutions. If you don't see them, it's one of the most important cognitive problems you have to solve.
—SA
AmitKPandey28 27-Jan-16 3:27am    
Thanks for your piece of advice...:) was very helpful!
Sergey Alexandrovich Kryukov 27-Jan-16 3:30am    
Sure. :-)
—SA

1 solution

Well, just do exactly that.

This is how you attach a click handler: .click() | jQuery API Documentation[^].

And this is how you clean up text values: .val() | jQuery API Documentation[^].

Assign empty string to the value, that's it. If you understand "clearing" differently, assign something else. :-)

Now, as to the drop-down lists, there is no such concept as "clearing". You can, for example, move selection to your predefined values, which may or may not be at the index 0. Such element it the element select. See, for example, How to set a dropdown box value in jQuery[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900