Click to See Complete Forum and Search --> : Textarea Value


greenpizza13
11-19-2003, 11:55 AM
Setting the value of a Textarea <br>
<hr>
<p>I'm designing a game that is sure to be a big hit. Look for it around january... heres a hint: Hacking. Its perfectly legal but it will be great. I need to know, is there a way to set the "value" of a textarea with JS? By value I mean whats inside the big box... If anyone can help me, I'd appriciate it.

fredmv
11-19-2003, 12:01 PM
<form action="#"><textarea rows="10" cols="50"></textarea><hr /><a href="#" onclick="elements[0].value='Hello, World';">Set value.</a>

greenpizza13
11-19-2003, 12:35 PM
How would I call it from a function my friend? And does the element[0] refer to all the form elements on the page, the textarea being the first one(0)...

fredmv
11-19-2003, 12:40 PM
Originally posted by greenpizza13
How would I call it from a function my friend?
Like this:<script type="text/javascript">
function changeValue(foo)
{
document.forms[0].elements['foo'].value = foo;
}
</script>
<form action="#">
<textarea name="foo" rows="10" cols="50"></textarea>
<hr />
<a href="#" onclick="changeValue('bar');">Hello, World.</a>
</form>Originally posted by greenpizza13
And does the element[0] refer to all the form elements on the page, the textarea being the first one(0)... It refers to the first element in the form, in this case, the textarea.