Select List transfer to another List with array

Discussion in 'Javascript' started by richardsith, Apr 20, 2012.

  1. richardsith

    richardsith

    Joined:
    Apr 20, 2012
    Messages:
    1
    Hello everyone,
    it's my first post here and I so sorry if I wrong the place.
    My difficulty is view the elements of the first select form to the other one if the first form is set as array.
    The goal is to send the elements of a select form to another one and then record them on a db MySQL, that will show them on a html page.
    I found in this forum the procedure how to create two select form and add 'n remove the items, then with the command .implode of MySQL can join the element and insert multiple items on db and view them on page.
    But if I set the name's select form as array it doesn't work. I've used the following script to have two select form :

    <script language="javascript">
    function getOpt(select1,select2)
    {
    for (bCnt=0;bCnt<select1.length;bCnt++)
    {
    if (select1.options[bCnt].selected)
    {
    newOpt=new
    Option(select1.options[bCnt].text,select1.options[bCnt].value,false,false);
    select2.options[select2.length]=newOpt;
    }
    }
    }

    function remOpt(select2)
    {
    for (bCnt=0;bCnt<select2.length;bCnt++)
    {
    if (select2.options[bCnt].selected)
    select2.options[bCnt]=null;
    }
    }
    </script>


    then the select form:

    <table border="0">
    <tr>
    <td>
    <label for="id">List:<br></label>
    <select name="oneS" id="select_role" size=20 required multiple="multiple"/>
    <option value="101">101</option>
    <option value="102">102</option>
    <option value="103">103</option>
    <option value="104">104</option>
    <option value="105">105</option>
    <option value="106">106</option>
    </select>
    </td>
    <td>
    <input type="button" value="Add"onClick="getOpt(this.form.oneS,this.form.twoS)"><br>
    <input type="button" value="Remove"onClick="remOpt(this.form.twoS)">
    </td>
    <td>
    <label for="id">Members List:<br></label>
    <select name="twoS" id="select_role" size=20 multiple="multiple"/>
    </select>
    </td>
    </tr>
    </table>

    if comment the script,the part of buttons, the second form and change the line:
    <select name="oneS" id="select_role" size=20 required multiple="multiple"/>

    in
    <select name="oneS[]" id="select_role" size=20 required multiple="multiple"/>
    I have any issue, can record the items on db and view them on the page, but it's not my goal. Is there some one can help me? please.
    Last edited: Apr 20, 2012
    richardsith, Apr 20, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. J. Hall
    Replies:
    2
    Views:
    1,044
    Jeff Thies
    Apr 21, 2004
  2. Jim
    Replies:
    1
    Views:
    847
    Aaron Bertrand - MVP
    Jan 28, 2004
  3. palmiere
    Replies:
    1
    Views:
    388
    Erwin Moller
    Feb 9, 2004
  4. WebRaster
    Replies:
    1
    Views:
    260
    Francisco Spaeth
    Oct 26, 2005
  5. carrajo

    Select List transfer to another List

    carrajo, Feb 16, 2006, in forum: Javascript
    Replies:
    5
    Views:
    301
Loading...

Share This Page