Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,501
    Thanks
    3
    Thanked 500 Times in 487 Posts
    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
    };
    Last edited by vwphillips; 01-13-2013 at 08:00 PM.
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •