Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
66
rated 0 times [  70] [ 4]  / answers: 1 / hits: 41749  / 13 Years ago, thu, december 29, 2011, 12:00:00

I want to know how to reset a particular form field using jQuery.



I'm using the folowing function:



function resetForm(id) {
$('#'+id).each(function(){
this.reset();
});
}


but it is resetting all the fields. Is there any way to reset specific fields using jQuery or JavaScript? I want to reset only a particular field.


More From » jquery

 Answers
12
function resetForm(id) {
$('#' + id).val(function() {
return this.defaultValue;
});
}


example without using id:



http://jsfiddle.net/vYWdm/


[#88329] Tuesday, December 27, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
frederickmohamedw

Total Points: 21
Total Questions: 123
Total Answers: 105

Location: The Bahamas
Member since Tue, Apr 27, 2021
3 Years ago
;