Tutorial :jQuery show/hide: How do you reset the value of a form element that is inside a show/hide div?


How do you reset the values of various types of form elements that are in a div when you use jQuery show/hide?


I am not sure if I get your question correctly, but the following jQuery magic will find your <div> element by id, hide it, find all <input> controls within it and "reset" their values to empty string.


If you need to target other form elements than <input> (such as <select> or <textarea>) you will need to add selectors for these as well. If you need to reset to other values (possible values provided in the original markup from the server), you will need to cache these values before the user gets to fiddle with the data in the form.


If memory serves, show/hide toggles the display attribute only. One should be able to modify the DOM in the same manner regardless of whether the elements are shown or not.


Resetting the values of form elements is going to be no different if they are hidden. Hide/show only change the display attribute, the elements still exist in the DOM.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »