Reputation: 275
Is there a way to remove Form input/select values when you hide a div?
Example: Let say i have a form that i fill out. I have a couple different choices, each one will show a different div with a different form and hide the rest. But when i submit, it still submits those form values, even when the div is hidden.
Is it possible to remove all hidden form values?
I prefer jQuery if possible.
Upvotes: 1
Views: 2486
Reputation: 7818
You could use the :hidden selector and disable all hidden inputs.
Ex:
$(':input:hidden').attr('disabled', true);
Edit: changed from null to disabled, simplified selector per suggestion by Chaos
Upvotes: 3
Reputation: 10180
You can iterate through all of the input elements of the hidden div and disable them. Disabled form inputs do not submit anything.
Upvotes: 2