views:

47

answers:

2

Hello folks,

Upon user interaction, I need to remove certain input params from an HTML form before submission. Using javascript to remove the input fields from the DOM doesn't seem to actually remove the params from being sent through the request.

Is there a way to delete or clear the actual request params?

+1  A: 

You could disable them.

formElement.disabled = true;
Kevin Crowell
+1. I can verify that disabling the element before the form is actually submitted works as intended. I even still had values in the elements that were disabled so the post data definitely did not contain the disabled elements.
Nitrodist
A: 

I am not sure if I am following your question exactly or not. But the way I read it, you have a set of fields in a form and when you submit, you are relying in the native form post behavior which places all the fields into the post.

My initial reaction would be to make the post yourself, using Ajax. Then you have complete control over what values are passed along and what are left behind.

That being said, if Ajax is not an option for whatever reason, what you could do is create a second, hidden form which is responsible for the actual posting. When you submit the visible form, you can copy the values you actually want submitted over to the hidden version, and them programatically post that one.

Mike Clark