Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.0k views
Welcome To Ask or Share your Answers For Others

1 Answer

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...