Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1500 How can I pass the values of selected options of a multiple select list to a textarea?

You are here: irt.org | FAQ | JavaScript | Form | Q1500 [ previous next ]

Try:

<form>
<select
onChange="if (this.selectedIndex >-1) {
   var t='';
   for (var i=this.selectedIndex;i<this.options.length;i++) {
      if (this.options[i].selected) t += this.options[i].value + '\n';
   }
   this.form.myTextarea.value = t;
}" multiple>
<option value="one">one
<option value="two">two
<option value="three">three
<option value="four">four
</select>

<textarea name="myTextarea" cols="10" rows="10"></textarea>
</form>

©2018 Martin Webb