Reputation: 75
I want to clear value of all inputs but except input type hidden which contains some value I want to submit on server.
What is the best way to select all form fields in a form but ignore hidden fields in the selection?
Upvotes: 5
Views: 6885
Reputation: 905
This jQuery selector worked for me. I am trying to get a list of all the fields inside a form that is an input element and is not a hidden input and is not a button
let formFields = jQuery('form.my-form').find(':input:not(:hidden):not(:button)');
Upvotes: 0
Reputation: 8623
As you mentioned inputs of a form:
$('form input:not([type=hidden])')
Upvotes: 0
Reputation: 40639
Use :hidden and :not() selectors like,
$('input:not(:hidden)').val('');
$(function() {
$('input:not(:hidden)').val('');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" value="one" /><br/>
<input type="text" value="two" /><br/>
<input type="hidden" value="one hidden" /><br/>
<input type="text" value="three" /><br/>
Upvotes: 3
Reputation: 390
You can try selecting like this:
$(":input:not([type=hidden])")
You can refer more here
Upvotes: 7
Reputation: 7441
Select all input fields which are not hidden.
jQuery('input[type!=hidden]').val('');
Upvotes: 2