<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Test</title><meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /><script type="text/javascript">
function fillTextarea(txt, name, min, max)
{
for(var i = min; i <= max; i++)
{
textarea = eval("document.myform." + name + i);
if(!textarea)
continue;
textarea.value = txt;
}
}
</script></head><body><form name="myform"><textarea name="textarea1"></textarea><br /><textarea name="textarea2"></textarea><br /><textarea name="textarea3"></textarea><br /><textarea name="textarea4"></textarea><br /><textarea name="textarea5"></textarea><br /><textarea name="textarea6"></textarea><br /><textarea name="textarea7"></textarea><br /><textarea name="textarea8"></textarea><br /><input type="button" onclick="fillTextarea('This is my string.', 'textarea', 1, 8)" value="Fill All" /></form></body></html>
This is just a modified version, taking four arugments
txt - The string you want to fill the textareas with.
name - The textarea names without the number (ie. if you had "description1" to "description8", the name without the number would be simply "description")
min - The minimum number suffix added to the name (in the above example, 1)
max - The maximum number suffix added to the name (in the above example, 8)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Test</title><meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /><script type="text/javascript">
function getObj(id)
{
var obj = false;
if(document.getElementById)
obj = document.getElementById(id);
else if(document.all)
obj = document.all[id];
else if(document.layers)
obj = document.layers[id];
return obj;
}
function hyperLink(textareaId)
{
textarea = getObj(textareaId);
if(!textarea)
return;
var linkname = prompt ( "Please Specify the name of your link..." );
var link = prompt ( "Please specify the location of the link..." );
textarea.value += '<a href="' + link + '">' + linkname + '</a>';
}
</script></head><body><form name="myform"><input type="button" value="Create Hyperlink" onclick="hyperLink('myeditor')"><br /><textarea id="myeditor" cols="25" rows="15"></textarea></form></body></html>
(I've included another function, getObj. You can use this and it will work with different DOM's. That is to say, old IE's and Netscapes, or those that don't support the W3C DOM.)
Anyway, instead of specifying the text as an argument, just create the text within the function.