Copy from a list to a textarea

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gram

    Copy from a list to a textarea

    Hello,

    Can anyone help me with the following, or point me to a site that can help:

    I have a list of words in a List and I want a user to be able to select
    several words from this list, hit a button and these words appear in a
    textarea.

    Thanks in advance for your help.

    Gram.


  • Lasse Reichstein Nielsen

    #2
    Re: Copy from a list to a textarea

    "Gram" <gram3000@hotma il.com> writes:
    [color=blue]
    > Hello,
    >
    > Can anyone help me with the following, or point me to a site that can help:
    >
    > I have a list of words in a List and I want a user to be able to select
    > several words from this list, hit a button and these words appear in a
    > textarea.[/color]

    I assume your "List" is a select element.

    Code:
    ---
    <script type="text/javascript">
    function transferWords() {
    var optsRef = document.getEle mentById("selec tId").options;
    var textRef = document.getEle mentById("texta reaId");
    var words = [];
    for (var i=0;i<optsRef.l ength;i++) {
    if (optsRef[i].selected) {
    words.push(opts Ref[i].text);
    }
    }
    textRef.value = words.join(" ");
    }
    </script>

    <select id="selectId" multiple="multi ple">
    <option>Some</option>
    <option>Words </option>
    <option>To</option>
    <option>Selec t</option>
    <option>From</option>
    </select>
    <input type="button" value="Transfer Words" onclick="transf erWords()">
    <textarea id="textareaId" >Words appear here</textarea>
    ---

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • W d'Anjos

      #3
      Re: Copy from a list to a textarea

      "Gram" <gram3000@hotma il.com> wrote in message news:<FYdgb.428 $1Q3.1526@news. indigo.ie>...[color=blue]
      > Hello,
      >
      > Can anyone help me with the following, or point me to a site that can help:
      >
      > I have a list of words in a List and I want a user to be able to select
      > several words from this list, hit a button and these words appear in a
      > textarea.
      >
      > Thanks in advance for your help.
      >
      > Gram.[/color]

      Gram,

      Check the attached code, I think is what you're looking for.

      Wagner

      -----
      <html>
      <head>
      <script language=JavaSc ript>
      function copy(){
      var o, i;
      with(document.m yform){
      myarea.value = '';
      for (i=0; i < mylist.options. length; i++){
      o = mylist.options[i];
      if (o.selected){
      if (myarea.value != '')
      myarea.value += '\n';
      myarea.value += o.text;
      }
      }
      }
      }
      </script>
      </head>
      <body>
      <form name=myform>
      <select name=mylist multiple>
      <option>Text 1
      <option>Text 2
      <option>Text 3
      <option>Text 4
      <option>Text 5
      <option>Text 6
      </select>
      <br><br>
      <input type=button name=mybtn value="Copy" onclick="copy() ;">
      <br><br>
      <textarea name=myarea rows=20>
      </textarea>
      </form>
      </body>
      </html>

      Comment

      • Gram

        #4
        Re: Copy from a list to a textarea

        Wagner

        Thats it, Thank you!

        Gram.


        Comment

        Working...