Jump to content

Interacting with PHP from JavaScript - Multiple Selects


tmyonline

Recommended Posts

Hi guys,

 

I have two lists; list A on the left and list B on the right.  List B is initially empty.  List A contains many options for users to select from.  So, list A allows multiple selects.  When a user makes a selection or multiple selections from list A, s/he will click the right arrow button (>>) and they will appear on list B.  Likewise, if s/he needs to remove an item, s/he will click the left arrow button (<<) to remove it from list B.  This is done entirely in JavaScript using a third party code.

 

Now, when the user clicks the submit button, these selected items from list B will be entered into a database on the server.  This is where I'm not sure how to do it due to the interaction between JavaScript and PHP.  Normally, suppose there is an input field like this:

 

<input name="item_A" value="item_A" />

 

To check if item_A successfully submitted, I usually do:

 

if (isset($_POST['item_A']) && $_POST['item_A'] != '')

  echo 'item A = ' . $_POST['item_A'];

 

Anyway, you probably know what I'm getting at.  I need to do the same kind of things for those items appeared on list B.  Here's an option that I've been thinking of - I want to put in an "onsubmit" attribute, like:

 

onsubmit="transferToServer();"

 

But, in my JavaScript transferToServer() function, how do I really transfer the list B items to the server so that they will be stored in some array, such as $_POST ?  If you have a better solution, please let me know.  I appreciate your help and thanks a lot.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.