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

  • Home
  • SEARCH
  • 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 8665091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:23:56+00:00 2026-06-12T17:23:56+00:00

I am using jQuery to make a search filter menu. This form contains several

  • 0

I am using jQuery to make a search filter menu. This form contains several form elements like checkbox and input box. When a user make some changes to the form and click on a #apply-filters button, the form will be hidden, and its data will be sent to the server backend for processing via $.post().

If the user made changes to the form but closes it without clicking the #apply-filters button, the filter menu div will be hidden, and the next time the user reopens the filter menu, the initial settings will be shown, not the most recent settings that the user made but failed to click on #apply-filters.

Problelm: What is the best way to do this in jQuery?

HTML

<form id="filter-menu">
    <input type="checkbox" id="free" name="free" /><label for="free">Free</label>
    <input type="checkbox" id="sale" name="sale" /><label for="sale">Sale</label>

    <input type="checkbox" id="rooms_1" name="rooms[]" value=1/><label for="rooms_1">1 Room</label>
    <input type="checkbox" id="rooms_2" name="rooms[]" value=2 /><label for="rooms_2">2 Rooms</label>

    <input type="text" id="price" val="100" />

    <button id="apply-filers">Apply Filters</button>
</form>

jQuery

$('#apply-filters').click(function() {
    $('#filter-menu').serializeArray();  // Gives an empty array

    $.post('api/someplace', 
            { free: 1,
            sale: 1,
            rooms: [1, 2],
            price: 100
            }, function() {
                console.log('yay');
            });
});

UPDATE

When I do

JSON.stringify($('filter-form').serializeArray())

I get

[{"name":"rooms[]","value":"1"},{"name":"rooms[]","value":"2"}]"

However I want to send it to server side via $.post() like

{rooms: [1,2]}

This way I will be able to do on the server side (PHP, after processing with the frameworks function)

$rooms = implode(',', $rooms_array)    // gives `1,2`

and the MySQL query can be like

SELECT .... WHERE rooms IN (1,2)

Is this possible? What would be a good way to send to the server side? Also, how would I use the output from serializeArray() to feed into $.post()?

  • 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-12T17:23:57+00:00Added an answer on June 12, 2026 at 5:23 pm

    Your serializeArray method returns empty array as your form elements have no name attributes.

    <input type="checkbox" id="free" name='something' />
    

    If you want to reset the form values you can use JavaScript reset method.

    $('#close').click(function(){
        $('#something').hide()
        $("#filter-menu")[0].reset();
    })
    

    $('#apply-filters').click(function() {
         var room = $('#filter-menu input[name="rooms[]"]:checked').map(function(){
                 return this.value
         }).get();  
    
        $.post('api/someplace', 
                { free: 1,
                sale: 1,
                rooms: room,
                price: 100
                }, function() {
                    console.log('yay');
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using jQuery UI to make some elements draggable and droppable. Much like
I'm currently using jQuery to make a div clickable and in this div I
i am using this jquery to make a drag and drop sortable list. http://jqueryui.com/demos/sortable/
I'm trying to implement a search box using php and jquery (the seach results
I have a form that takes a city as input, then I'm using jQuery
I am trying to make dropdown enabling using jquery and click search then that
i'm trying to make my image search with google ajax search i'm using jQuery.
http://jsfiddle.net/nFFuD/ I'm trying to animate the search field in this example using jquery, making
im using jquery to make ajax requests. is it possible to detect if the
I am using jQuery to make a POST to a PHP file with the

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.