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:
Now what I really want is to pass a variable into the function which will contain how many textareas need to be filled.Code:<html> <head> <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; } } </script> </head> <body> <textarea rows='5' cols='30' id="a"></textarea> <input type="checkbox" onclick="copyText()" /><br><br><br> <textarea rows='5' cols='30' id="b"></textarea> </body> </html>
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?


Reply With Quote
Bookmarks