jquery multiselect form handling

Posted on 2008-11-13
Last Modified: 2013-12-13
jQuery is not posting my multiselect forms as arrays, it is posting them as the same value definied three times.

For instance...
If I choose the values '1', '2', and '3' from a multiselect "chooseme",
I will get a php environment with chooseme = 3 when I submit the request through jQuery ajax post json.  I use firebug to look at the POST request and I can see it sending "chooseme = 1", "chooseme = 2", and "chooseme = 3".  The thing is I think each time chooseme is being defined in the POST request, it is overwriting the previous value.

However when I send the request as just a standard html request from my browser, it goes into php as an Array.

Can anyone tell me how to get jQuery to submit multiselect form field via AJAX and get an array to arrive at PHP?
Question by:siteup1

    Author Comment

    FYI this is the relevant jquery code i'm using, paired down for simplicity.  You'll notice i'm using JSON as the transport data type.

    Any ideas on why this isn't sending in all values for the multiselect?
      //run ajax
        $.post("step1ajax.php",{products: $("select#products").val(), tag: $("select#tag").val(), ajax: 'true'}, function(j){
          //update the number records div display
          var updaterecordshtml = '<p>There are <strong>' + j.records + ' records</strong> meeting that criteria.</p>';

    Open in new window

    LVL 42

    Accepted Solution

    It is sending them. PHP just can't read more than one of them like that. change the name from "chooseme" to "chooseme[]". The square brackets will make PHP treat it like an array which will allow you to access all of the values.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question ( on how to make a page show some balloons animate up a page…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now