Tiep Pt
Tiep Pt

Reputation: 75

How to get value of all inputs not type hidden

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

Answers (6)

AhmadKarim
AhmadKarim

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

huan feng
huan feng

Reputation: 8623

As you mentioned inputs of a form:

  $('form input:not([type=hidden])')

Upvotes: 0

Rohan Kumar
Rohan Kumar

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

TinDora
TinDora

Reputation: 390

You can try selecting like this:

$(":input:not([type=hidden])")

You can refer more here

Upvotes: 7

perseusl
perseusl

Reputation: 348

have you tried $('input[type!=hidden]') ?

Upvotes: 0

unalignedmemoryaccess
unalignedmemoryaccess

Reputation: 7441

Select all input fields which are not hidden.

jQuery('input[type!=hidden]').val('');

Upvotes: 2

Related Questions