views:

260

answers:

3

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.

+3  A: 
$(divyoujusthid).find(':input').attr('disabled', true);
chaos
You can shorten the find to ':input'
Paolo Bergantino
Oh, slick. Thanks. Edited per. :)
chaos
With disabling, there seems to be a problem with IE7.Instead, i remove the values:$(':input:hidden').val("");
Ricky
+2  A: 

You can iterate through all of the input elements of the hidden div and disable them. Disabled form inputs do not submit anything.

Kevin Crowell
+3  A: 

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

Jimmie R. Houts
Suggest also using :input:hidden per Paolo Bergantino's comment to my answer.
chaos
updated... I must say that is awesome! Thanks Paolo and chaos :)
Jimmie R. Houts
Doesnt seem to work correctly in IE7.
Ricky