• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1423
  • Last Modified:

jquery multiselect form handling

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?
0
siteup1
Asked:
siteup1
1 Solution
 
siteup1Author Commented:
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
  $("select").change(function(){
    $.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>';
      $("div#numRecords").html(updaterecordshtml);
    },"json")
  })

Open in new window

0
 
David S.Commented:
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.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now