Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
146
rated 0 times [  148] [ 2]  / answers: 1 / hits: 20907  / 11 Years ago, wed, august 21, 2013, 12:00:00

I need to reset forms elements after click span for example.



Is there a method to reset the from by jQuery without select each element and remove the attribute value.



Some of the elements not having attribute value like textarea or radio



And some like button I don't want to remove the value from it.



I want use jQuery to use the reset on other events



Code for example http://jsfiddle.net/pgNrF/



<input type=button value=Input Button>
<input type=checkbox>
<input type=hidden>
<textarea></textarea>
<span>Reset</span>

More From » jquery

 Answers
1

This is already built in if you wrap those form elements in an actual form:


<form id="myform">  
<input type="button" value="Input Button">
<input type="checkbox">
<input type="file">
<input type="hidden">
<input type="image">
<input type="password">
<input type="radio">
<input type="submit">
<input type="text">
<select>
<option>Option1</option>
<option>Option2</option>
<option>Option3</option>
</select>

<textarea></textarea>
<button type="button">Button</button>

<button type="reset">Reset</button>
</form>

FIDDLE


If you just have to use jQuery:


$('span').click(function() {
$('#myform').get(0).reset();
});

FIDDLE


[#76240] Tuesday, August 20, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
denism

Total Points: 627
Total Questions: 96
Total Answers: 98

Location: Ivory Coast
Member since Sun, Mar 7, 2021
3 Years ago
;