CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   multiple dropdown lists (http://www.codingforums.com/showthread.php?t=285712)

hyster 01-13-2013 02:22 PM

multiple dropdown lists
 
im very new to JS, much prefer php but the only way i could do what i want is using JS.
i took 2 pieces of JS i found. i managed to get the 1st 1 doing what i wanted but id like to be able to set it up like the 2nd piece of code underneath so i can enter it into a database as an array.

so basicly a user selects multple tanks and adds it to a form the submits to a database.

examples here http://amp.net84.net/java/

i carnt work out enough of the code to merge them into what i want.
hope ive explained enough.

gratefull to any pointers.

vwphillips 01-13-2013 07:46 PM

Code:


script removed to allow posting
</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<TABLE>
<tr>
  <td>col 1</td>
  <td></td>
  <td>col 2</td></tr>
  <TR>
        <TD> <select size="5"  name="lstBox" id="lstBox">
        <option value="A">A</option>
                <option value="D">D</option>
                        <option value="C">C</option>
                        <option value="E">E</option>
                        <option value="B">B</option>

        </select>
</TD>
<TD> <input name="add" type="button" value="Add" onclick="FirstListBox();" /> <input name="remove" type="button" value="Remove" onclick="SecondListBox();"/></TD>
        <TD>
        <select size="5" name="ListBox1" id="ListBox1">

        </select>
        </TD>
</TABLE>
</form>

<SCRIPT type="text/javascript">
<!--
        function SecListBox(ListBox,text,value)
        {
        try
        {
        var option=document.createElement("OPTION");
        option.value=value;
        option.text=text;
        ListBox.options.add(option)
        }
        catch(er)
        {
        alert(er)
        }
        }

        function OutPut(){
    for (var s=document.getElementById("ListBox1"),txt='',z0=0;z0<s.length;z0++){
      txt+=s.options[z0].value+':';
    }
    document.getElementById('ip').value=txt;
        }

    function FirstListBox(){
    var count=document.getElementById("lstBox").options.length;
        for(var i=0;i<count;i++){
          if(document.getElementById("lstBox").options[i].selected){
          SecListBox(document.getElementById("ListBox1"),document.getElementById("lstBox").options[i].value,document.getElementById("lstBox").options[i].value);document.getElementById("lstBox").remove(i);
      break
    }
          }
    OutPut();
        }

        function SortAllItems(){
        var arr=new Array();
        for(i=0;i<document.getElementById("lstBox").options.length;i++)        {
        arr[i]=document.getElementById("lstBox").options[i].value}arr.sort();
        RemoveAll();
        for(var i=0;i<arr.length;i++){
          SecListBox(document.getElementById("lstBox"),arr[i],arr[i])}}function RemoveAll(){try{document.getElementById("lstBox").options.length=0
    }
        catch(er){
      alert(er)
    }
        }

        function SecondListBox(){
    var count=document.getElementById("ListBox1").options.length;
        for(var i=0;i<count;i++){
          if(document.getElementById("ListBox1").options[i].selected){SecListBox(document.getElementById("lstBox"),document.getElementById("ListBox1").options[i].value,document.getElementById("ListBox1").options[i].value);document.getElementById("ListBox1").remove(i);
            break
          }
    }
        SortAllItems()
    OutPut();
        }
//-->
</SCRIPT>

<!-- Hosting24 Analytics Code -->
<script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>
<!-- End Of Analytics Code -->

</body>
</html>

also

Code:

SList.slist2 = {
 "sov": ['Sov_Light', 'Sov_Medium', 'Sov_Heavy', 'Sov_TD', 'Sov_SPG'],
 "ger": ['Ger_Light', 'Ger_Medium', 'Ger_Heavy', 'Ger_TD', 'Ger_SPG'],
 "usa": ['Usa_Light', 'Usa_Medium', 'Usa_Heavy', 'Usa_TD', 'Usa_SPG'],
  "brit": ['Brit_Light', 'Brit_Medium', 'Brit_Heavy', 'Brit_TD', 'Brit_SPG'],
  "french": ['Fre_Light', 'Fre_Medium', 'Fre_Heavy', 'Fre_TD', 'Fre_SPG'],
  "chin": ['Chin_Light', 'Chin_Medium', 'Chin_Heavy', 'Chin_TD', 'Chin_SPG']  // < no commer
};



All times are GMT +1. The time now is 02:45 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.