Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove empty fields from my form in the querystring?

I have a simple form with four inputs. When I submit my form, I want to use the GET http method.

For the example :

aaa : foo bbb : ____ ccc : bar ddd : ____ 

I want to have this query string :

/?aaa=foo&ccc=bar 

The problem is I have this query string :

/?aaa=foo&bbb=&ccc=bar&ddd= 

How can I remove empty fields from my form in the query string ?

Thanks.

like image 967
Sandro Munda Avatar asked May 08 '11 09:05

Sandro Munda


People also ask

What is Querystring in Javascript?

A query string is part of the full query, or URL, which allows us to send information using parameters as key-value pairs.


1 Answers

You could use jQuery's submit function to validate/alter your form:

<form method="get" id="form1">     <input type="text" name="aaa" id="aaa" />      <input type="text" name="bbb" id="bbb" />      <input type="submit" value="Go" /> </form> <script type="text/javascript">     $(document).ready(function() {         $("#form1").submit(function() {             if($("#bbb").val()=="") {                     $("#bbb").remove();             }         });      }); </script> 
like image 85
RaphDG Avatar answered Sep 20 '22 06:09

RaphDG