Get/Set a value into a Textarea

In javascript you might have a form with lots of textareas, textboxes, radio buttons, checks checked off or not... lots of stuff going on in a particular form. HTML is funny - it gets All the information from a particular form all at once. If something is in a form - you talk to the form first, then to the particular object inside that form. That's because you may have more than one form on a page.

First we Name our form that's on our html page:

<FORM NAME = "form1">
<TEXTAREA NAME = "Textarea" COLS = 30 ROWS = 10></TEXTAREA>
<BR>
<BR>
<INPUT TYPE = BUTTON Value = "Display Message" onClick = "DisplayMessage()">
</FORM>

Next, we Name our textarea that's in this form:

<FORM NAME = "form1">
<TEXTAREA NAME = "Textarea" COLS = 30 ROWS = 10></TEXTAREA>
<BR>
<BR>
<INPUT TYPE = BUTTON Value = "Display Message" onClick = "DisplayMessage()">
</FORM>

Next, we fix up our button:

In the "onClick" event - we send a javascript function

<FORM NAME = "form1">
<TEXTAREA NAME = "Textarea" COLS = 30 ROWS = 10></TEXTAREA>
<BR>
<BR>
<INPUT TYPE = BUTTON Value = "Display Message" onClick = "DisplayMessage()">
</FORM>

Now, we can stick those names in a little javascript and do something with the form...

<SCRIPT LANGUAGE = JavaScript>

var myVariable
function DisplayMessage()
{
form1.Textarea.value = "Hello from JavaScript"
}
</SCRIPT>

To Set the value into a textarea you tell javascript which object you want on the left, and the value you want in it on the right.

form1.Textarea.value = "Hello from JavaScript"

The code to Get the value from a textarea is: (you put the variable on the left, the value going into the variable on the right)

myVariable = form1.Textarea.value

so the whole script for getting the value from a textarea is:

<SCRIPT LANGUAGE = JavaScript>

var myVariable
function DisplayMessage()
{
myVariable = form1.Textarea.value
}
</SCRIPT>