Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove the Name attribute of hidden input fields using Jquery?

Tags:

jquery

I have multiple input fields on a form like below:

<div class="ginput_container ginput_container_product_calculation">
<input type="hidden" class="gform_hidden" value="Space Cost:" name="input_97.1">
<input type="hidden" class="gform_hidden" value="$150.00" name="input_97.2">
<input type="hidden" class="ginput_quantity_1_97 gform_hidden" value="1" name="input_97.3">
</div>

I need to prevent all hidden input fields in the form from being submitted. The best solution I found so far is to remove the name attributes of input fields but I've no idea how it can be done using jQuery. Any help would be appreciated!

like image 536
Alex Avatar asked Feb 07 '23 06:02

Alex


1 Answers

Use .removeAttr().

$("input[type='hidden']").removeAttr('name');

OR

$(":hidden").removeAttr('name');

OR

$("input:hidden").removeAttr('name');

Edit :- Another way to disallow some inputs to post is to make them disabled as disabled form inputs are not submitted.

like image 115
Kartikeya Khosla Avatar answered Feb 13 '23 06:02

Kartikeya Khosla