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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to add values to a list box 1

Status
Not open for further replies.

kirankumar

Programmer
May 17, 2000
25
US
Hi,<br>I have two list boxes on my form. What i need to do is to add the values selected in the first list box to the second list box. Both have multiple selection option enabled.<br><br>Thanks in advance
 
Dear kirankumar,<br><br>Where your form is named 'form1' and your two 'select' elements are named 'select1' and 'select2' this would work:<br><br>function cmdCopy_onclick() {<br><br>&nbsp;&nbsp;for(i=0;i&lt;document.form1.select1.options.length; i++){<br>&nbsp;&nbsp;&nbsp;&nbsp;document.form1.select2.options.add( <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.form1.select1.options(i));<br>&nbsp;&nbsp;}<br>}<br><br>Good luck<br>-pete<br>
 
Dear Pete,<br><br>I tried with the same code. But its not working. I am getting the alert but not the new values in select box2. Here is the code in the command button click event.<br><br>function assign()<br>{<br>var intlength;<br>intlength=window.document.frmassign.select1.options.length;<br>alert(intlength);<br>var temp;<br>for (var i = 0; i &lt; intlength; i++)<br>{<br>temp = window.document.frmassign.select1.options(i).value;<br>alert(temp); <br>window.document.frmassign.select2.options.add(window.document.frmassign.select1.options(i));<br>} <br>}<br><br>I already done the same thing. But somewhere it's going wrong. <br>Thank you for your help and time.<br><br>Kiran<br>
 
yes, replace that part :<br><br>temp = window.document.frmassign.select1.options(i).value;<br>window.document.frmassign.select2.options.add(window.document.frmassign.select1.options(i));<br><br>------<br>with that one :<br>var temp = window.document.frmassign.select1.options(i).value;<br>var temp2 = window.document.frmassign.select1.options(i).text;<br>var oOption = document.createElement(&quot;OPTION&quot;);<br>oOption.text=temp;<br>oOption.value=temp2;<br>window.document.frmassign.select2.options.add(oOption)<br><br><br>and it might b ok<br>tell me if it's not
 
Hi ija,<br>Thank you very much. It's working. Really you helped me a lot.<br><br>Thank you agian.<br><br>Kirankumar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top