Results 1 to 2 of 2

Thread: Copy textarea contents to other textareas

  1. #1
    Join Date
    Mar 2009

    Copy textarea contents to other textareas

    I'm using a form where a user enters data in a textarea which is then copied to all other textareas on the page. Currently I have it working for 2 textareas using this code:

    <script type="text/javascript" language="javascript">
    function copyText()
    var a = document.getElementById('a');
    var b = document.getElementById('b');
    if (a != null)
    b.value = a.value;
    <textarea rows='5' cols='30' id="a"></textarea>
    <input type="checkbox" onclick="copyText()" /><br><br><br>
    <textarea rows='5' cols='30' id="b"></textarea>
    Now what I really want is to pass a variable into the function which will contain how many textareas need to be filled.
    So my function psueudocode might look like:

    function copytext(number)
    for i=0 to number
    do (copy text areas)

    My question is how I name each textarea id on the fly using my loop and hence bening able to use its .value attribute. Or is there an easier way to do it?

  2. #2
    Join Date
    Apr 2003
    If you are going to reference the textareas consecutively, use document.getElementsByTagName('textarea')
    At least 98% of internet users' DNA is identical to that of chimpanzees

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center