Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving Values Between Select Boxes

Status
Not open for further replies.

nicasa

Programmer
Feb 3, 2003
54
ES
Hi Gurus,

I am Moving Values Between Select Boxes using the following code snippet ...

<TABLE BORDER=0>
<TR>
<TD>
<SELECT NAME="list1" MULTIPLE SIZE=10 >
<OPTION VALUE="G723">G.723.1</OPTION>
<OPTION VALUE="gsm">GSM</OPTION>
<OPTION VALUE="g726">G.726-32</OPTION>
<OPTION VALUE="adpcm">ADPCM</OPTION>
<OPTION VALUE="slin">SLIN</OPTION>
<OPTION VALUE="g729">G.729</OPTION>
<OPTION VALUE="ilbc">ILBC</OPTION>
</SELECT>
</TD>

<TD VALIGN=MIDDLE ALIGN=CENTER>
<INPUT TYPE="button" NAME="right" VALUE="&gt;&gt;" ONCLICK="opt.transferRight()"><BR><BR>
<INPUT TYPE="button" NAME="right" VALUE="All &gt;&gt;" ONCLICK="opt.transferAllRight()"><BR><BR>
<INPUT TYPE="button" NAME="left" VALUE="&lt;&lt;" ONCLICK="opt.transferLeft()"><BR><BR>
<INPUT TYPE="button" NAME="left" VALUE="All &lt;&lt;" ONCLICK="opt.transferAllLeft()">
</TD>

<TD>
<SELECT NAME="list2" MULTIPLE SIZE=10 >
<OPTION VALUE="ulaw">G.711u-Law</OPTION>
<OPTION VALUE="alaw">G.711a-Law</OPTION>
</SELECT>
</TD>
</TR>
</TABLE>

Does anyone have a simpler solution that uses arrays like
list1[] and list2[] ?

Thanks !

Steven M
 
i see no javascript code. You could use arrays, yah.
I would google for it, try something then post some code when u run into an error.
 
Code:
<html>
	<script type="text/javascript">
		function transRight(){
			list1 = document.getElementById('list1');
			list2 = document.getElementById('list2');
			for(var i=0;i<list1.options.length;i++){
				if(list1.options[i].selected){
					list2.options[list2.options.length] = new Option(list1.options[i].value,list1.options[i].text);
					list1.options[i]=null;
				}
			}
		}
		function transLeft(){
			list1 = document.getElementById('list1');
			list2 = document.getElementById('list2');
			for(var i=0;i<list2.options.length;i++){
				if(list2.options[i].selected){
					list1.options[list1.options.length] = new Option(list2.options[i].value,list2.options[i].text);
					list2.options[i]=null;
				}
			}
		}
	</script>
	<body>
		<select id="list1" size="6" MULTIPLE>
			<option value="test01">test01</option>
			<option value="test02">test02</option>
			<option value="test03">test03</option>
			<option value="test04">test04</option>
			<option value="test05">test05</option>
			<option value="test06">test06</option>
		</select>
		<button type="button" onclick="transLeft()">left</button>
		<button type="button" onclick="transRight()">right</button>
		<select id="list2" size="6" MULTIPLE>
			<option value="test07">test07</option>
			<option value="test08">test08</option>
			<option value="test09">test09</option>
			<option value="test10">test10</option>
			<option value="test11">test11</option>
			<option value="test12">test12</option>
		</select>
	</body>
</html>
slow day @ werk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top