Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9070689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:44:41+00:00 2026-06-16T17:44:41+00:00

i am building a search function which use many filters. i decide to use

  • 0

i am building a search function which use many filters. i decide to use the get method instead of post (different reasons). Problem is, when using many filters the querystring gets very long, especially when i use filter with same name so i get

myurl.com?filter1[]=val1&filter1[]=val2&filter2=val

To get better control and to prevent 0 values i tried serializeArray:

var array = {}; 
jQuery.each(jQuery('form').serializeArray(), function(index,val) {
if (val.value != 0 )
    array[value.name] = val.value;
});

But this way it overrides the first filter1 with the last value of filter1, so multiple values doesn´t work. And then i have the “problem” to create the querystring. I am not a javascript prof. so i need a little help here.

What can i do, so i get a querystring which looks like:

myurl.com?filter1=val1|val2&filter2=val and so on

The HTML are “normal” input fields

<input type="checkbox" name="filter1[]" />
<input type="text" name="filter2" />

Thank you in advance

ruven

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T17:44:42+00:00Added an answer on June 16, 2026 at 5:44 pm

    How about this (working demo):

    <form action="search.html">
        <input type="text" value="val1" name="filter1" />
        <input type="text" value="val2" name="filter1" />
        <input type="text" value="val" name="filter2" />
        <input type="submit" value="search" name="cmdSearch" />
    </form>
    ​
    <script>
        // don't do anything until document is ready
        $(function() {
    
            // register to form submit event
            $('form').submit(function(e){
    
                // stop the form from doing its default action (submit-GET)
                e.preventDefault();
    
                // initialise url
                var url = '';
    
                // keep track of previously enumerated field
                var prev = '';      
    
                // iterate all fields in the form except the submit button(s)
                $('input:not([type="submit"])', $(this)).each(function(){
    
                    // get the name of this field, with null coalesce
                    var name = $(this).attr('name') || '';
    
                    // get the value of this field
                    var val = $(this).attr('value');
    
                    // does this field have the same name as the previous?
                    if (name.toLowerCase() == prev.toLowerCase()) {
    
                        // same name therefore we have already appended the name
                        // append value separator
                        url += '|';
                    }
                    else {
    
                        // different name, track new name
                        prev = name;
    
                        // append parameter separator, parameter name, equals char
                        url += '&' + name + '=';
                    }
    
                    // append value of this field         
                    url += val;
                });
    
                // removing leading ampersand
                if (url.length && [0] == '&') {
                    url = url.substring(1);            
                }       
    
                // insert leading question mark
                url = '?' + url;
    
                // insert url from "action" attribute of the form
                url = $(this).attr('action') + url;
    
                // display url (delete this line)
                alert(url);
    
                // redirect to the new url (simulates the GET)
                window.location.href = url;
            });
        });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building an iPhone app, which will function similarly to many restaurant finder
I am building a Search function for a shopping cart site, which queries a
I'm building a little search application (I know I can use match against). But
I am building a custom search control in VB.NET and came across a problem
I'm currently exploring the different options for building a not-too-complex web application, in which
I need to build an ajax search function which, as the user types, will
I have a search box which has an auto-complete feature that I've been building.
I am building a little search function for my site. I am taking my
I'm building a basic search function for my site. Realising that the most useful
I am building a code which displays user information on search. User information, is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.