Java Reference
In-Depth Information
The purpose of clearEventLog() is to clear the contents of the second <textarea/> element, and it
achieves this by setting the <textarea/> element's value property to an empty string ( "" ).
Now let's look at the displayEvent() function. It adds the name of the event that occurred to the text
already contained in the second text area:
function displayEvent(e) {
var message = textArea2.value;
message = message + e.type + "\n";
You first retrieve the <textarea/> element's value and store it in the message variable. You then
append the name of the event as well as a new line to the message. Putting each event name on a
separate line makes it much easier to read and follow.
Then finally, you assign the new message to the text area's value property:
textArea2.value = message;
}
Check boxes and radio buttons
The discussions of check boxes and radio buttons are together because their objects have identical
properties, methods, and events. A check box enables the user to check and uncheck it. It is
similar to the paper surveys you may get where you are asked to “check the boxes that apply
to you.” Radio buttons are basically a group of check boxes where only one can be checked at
a time. Of course, they also look different, and their group nature means that they are treated
differently.
Creating check boxes and radio buttons requires our old friend the <input/> element. Its type
attribute is set to "checkbox" or "radio" to determine which box or button is created. To set a
check box or a radio button to be checked when the page is loaded, you simply insert the attribute
checked into the <input> tag and assign its value as checked . This is handy if you want to set a
default option like, for example, those “Check this box if you want our junk mail” forms you often
see on the Net, which are usually checked by default, forcing you to uncheck them. So to create a
check box that is already checked, your <input> tag will be the following:
<input type="checkbox" name="chkDVD" checked="checked" value="DVD" />
To create a checked radio button, the <input> tag would be as follows:
<input type="radio" name="radCPUSpeed" checked="checked" value="1 GHz" />
As previously mentioned, radio buttons are group elements. In fact, there is little point in putting
just one on a page, because the user won't be able to choose between any alternative boxes.
To create a group of radio buttons, you simply give each radio button the same name . This creates an
array of radio buttons going by that name that you can access, as you would with any array, using
its index.
 
Search WWH ::




Custom Search