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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.