PDA

View Full Version : Remove value from form on submit



>ssp-cdr<
Jun 7th, 2012, 07:19 AM
As part of a search form I am working on there is a series of three radio boxes to select "Everything", "Buildings", or "Cities". The form is submitted using the GET method so that all the search criteria from the from gets put into the URL. To streamline the appearance of the URL I would like to not have the name=value pair appear if "Everything" is selected.

I tried excluding a value for it but it seems that web browsers put in a default value of "on".

I've thought of not giving the radio button a name (so that no name=value pair would pass through to the URL) and using onClick events to handle the proper selection settings amongst the radio boxes. This would work but what I would really like to do is...

When the form is submitted, before the browser creates the URL to request, use JavaScript to access the DOM and remove the occurrence of the radio box if the "Everything" box is selected, but without removing the radio box from the actual page so that the user doesn't see anything strange happening.

Can anyone give me advice on this? Thanks.

Krupski
Jun 7th, 2012, 07:21 AM
As part of a search form I am working on there is a series of three radio boxes to select "Everything", "Buildings", or "Cities". The form is submitted using the GET method so that all the search criteria from the from gets put into the URL. To streamline the appearance of the URL I would like to not have the name=value pair appear if "Everything" is selected.

I tried excluding a value for it but it seems that web browsers put in a default value of "on".

I've thought of not giving the radio button a name (so that no name=value pair would pass through to the URL) and using onClick events to handle the proper selection settings amongst the radio boxes. This would work but what I would really like to do is...

When the form is submitted, before the browser creates the URL to request, use JavaScript to access the DOM and remove the occurrence of the radio box if the "Everything" box is selected, but without removing the radio box from the actual page so that the user doesn't see anything strange happening.

Can anyone give me advice on this? Thanks.

Can't you use "post" instead of "get"? That way, nothing will show in the URL.

>ssp-cdr<
Jun 7th, 2012, 07:44 AM
But I want the search criteria to be in the URL, just not blank name=value pairs. People will be able to link to search result pages if the URL has all of the search criteria.

>ssp-cdr<
Jun 10th, 2012, 12:53 PM
*bump*


:o

>ssp-cdr<
Jun 10th, 2012, 10:04 PM
The only other form data is a text field.

Here's a screen shot so you can get an idea of what's going on.

I simply don't want the &w= appearing in the URL when there is no value associated with it. w is the name for the set of radio buttons.

http://gingert.net/images/searchexample.jpg

felgall
Jun 11th, 2012, 12:30 AM
Set the fields you don't want to send to disabled = true; prior to submitting the form. That will get rid of them for those people with JavaScript enabled.

>ssp-cdr<
Jun 11th, 2012, 12:26 PM
fegall, what a great idea, it works. Thanks! :)