Reputation: 4606
How I need to RESET a form without touching "hidden" input and "submit", I tried the follow but doesn't works,
$("#myForm textarea input[type!='submit'] input[type!='hidden']").val('');
How can I do it using Jquery?
Upvotes: 1
Views: 448
Reputation: 318468
$("#myForm :input:not(:hidden):not(:submit)").val('');
Note that :hidden
also selects hidden elements - if you want only type="hidden"
form elements but not e.g. a hidden type="text"
element, use [type="hidden"]
instead.
Or maybe you simply want to do $('#myForm')[0].reset();
Upvotes: 2
Reputation: 35793
Easiest way is to select all input fields and then filter out what you don't want and reset the ones you are left with.
$("#myForm :input").filter(function() {
return !($(this).is(':submit') || $(this).attr('type') == 'hidden');
}).val('');
http://jsfiddle.net/infernalbadger/rpRqX/
Alternative without using filter:
$("#myForm :input").not(':submit').not('[type="hidden"]').val('');
http://jsfiddle.net/infernalbadger/rpRqX/1/
Upvotes: 2