Ricky
Ricky

Reputation: 275

Remove Values from Hidden Div Forms

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

Answers (3)

Jimmie R. Houts
Jimmie R. Houts

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

Kevin Crowell
Kevin Crowell

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

chaos
chaos

Reputation: 124297

$(divyoujusthid).find(':input').attr('disabled', true);

Upvotes: 3

Related Questions