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!

paste multi-selected

Status
Not open for further replies.

JuRo

Programmer
Nov 24, 2002
5
AT
Hi,
please, if you could help me out with this:
I have: an input type=text field and a select multiple field in two different formulars.
I need: to paste the picked out entries (&quot;'<option>'s&quot;) from the select-multiple field into a input text field.

This thing is kind of too big for me.
I thank you.

Juro
 
If I understand your question, this should solve your problem (tested in IE5 and NN4):-

<HTML>
<HEAD>
<TITLE>Select into Textbox</TITLE>

<SCRIPT>
<!--

function getOpts() {
var outStr =&quot;&quot;;
for (i=0;i<document.myForm.mySel.options.length;i++) {
if (document.myForm.mySel.options.selected)
{
outStr = outStr + document.myForm.mySel.options.text + &quot; &quot;;
}
}
if (outStr == &quot;&quot;) outStr = &quot;nothing selected&quot;;
document.myForm.outText.value = outStr;
}

-->
</SCRIPT>
</HEAD>

<BODY>
<FORM NAME=&quot;myForm&quot;>
<P><B>Select a few options:-</B>
<P><SELECT NAME=&quot;mySel&quot; MULTIPLE>
<OPTION>ONE
<OPTION>TWO
<OPTION>THREE
<OPTION>FOUR
<OPTION>FIVE
<OPTION>SIX
<OPTION>SEVEN
<OPTION>EIGHT
<OPTION>NINE
<OPTION>TEN
</SELECT>
<BR><BR>
<P>
<INPUT type=&quot;button&quot; value=&quot;Go!&quot; onClick=&quot;getOpts();&quot;>
<BR><BR>
<P>
<INPUT type=&quot;text&quot; name=&quot;outText&quot; value=&quot;none selected&quot;>
</FORM>
</BODY>
</HTML>

Enjoy :)
[sig][/sig]
 
Actually, this is better because it uses an onChange handler rather than the Go! button. Have also added a reset button to undo previous selections :)

<HTML>
<HEAD>
<TITLE>Select into Textbox</TITLE>

<SCRIPT>
<!--

function getOpts() {
var outStr =&quot;&quot;;
for (i=0;i<document.myForm.mySel.options.length;i++) {
if (document.myForm.mySel.options.selected)
{
outStr = outStr + document.myForm.mySel.options.text + &quot; &quot;;
}
}
if (outStr == &quot;&quot;) outStr = &quot;nothing selected&quot;;
document.myForm.outText.value = outStr;
}

function rstOpts() {
for (i=0;i<document.myForm.mySel.options.length;i++) {
if (document.myForm.mySel.options.selected)
{
document.myForm.mySel.options.selected = false;
}
}
document.myForm.outText.value = &quot;none selected&quot;;
}

//-->
</SCRIPT>
</HEAD>

<BODY>
<FORM NAME=&quot;myForm&quot;>
<P><B>Select a few options:-</B>
<P><SELECT NAME=&quot;mySel&quot; MULTIPLE onChange=&quot;getOpts();&quot;>
<OPTION>ONE
<OPTION>TWO
<OPTION>THREE
<OPTION>FOUR
<OPTION>FIVE
<OPTION>SIX
<OPTION>SEVEN
<OPTION>EIGHT
<OPTION>NINE
<OPTION>TEN
</SELECT>
<BR><BR>
<P>
<INPUT type=&quot;button&quot; value=&quot;Reset&quot; onClick=&quot;rstOpts();&quot;>
<BR><BR>
<P>
<INPUT type=&quot;text&quot; name=&quot;outText&quot; value=&quot;none selected&quot;>
</FORM>
</BODY>
</HTML>

Enjoy (even more) ;-) [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top