Java Reference
In-Depth Information
Figure 7-6
Next, you have an empty text area the same size as the fi rst.
<textarea rows=”15” cols=”40” name=”textarea2”></textarea>
Finally, you have your button element.
<input type=”button” value=”Clear Event TextArea” name=”button1”
onclick=”document.form1.textarea2.value=''“ />
Notice that the onclick event handler for the button is not calling a function, but just executing a line
of JavaScript code. Although you normally call functions, it's not compulsory; if you have just one
line of code to execute, it's easier just to insert it rather than create a function and call it. In this case, the
onclick event handler is connected to some code that clears the contents of the second text area by
setting its value property to an empty string ('').
Now let's look at the displayEvent() function. This is defi ned in a script block in the head of the page.
It adds the name of the event handler that has been passed as a parameter to the text already contained
in the second text area.
function displayEvent(eventName)
{
var myMessage = document.form1.textarea2.value;
myMessage = myMessage + eventName;
document.form1.textarea2.value = myMessage;
}
Search WWH ::




Custom Search