Manish Jangir Manish Jangir - 5 months ago 30
Javascript Question

How to reset a particular form field using jQuery

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.

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

example without using id:

http://jsfiddle.net/vYWdm/

Comments