In our last article we left off with a glimpse of JavaScript Events. In this tutorial we are going to go through each one and learn how to use them to create more dynamic web sites. So slap on your seat belts and get your helmets ready. This is gonna be an action-packed episode.
The OnClick Event is triggered when someone clicks an object. There are a variety of uses for this, but we are going to use it to concatenate two fields into one.
<html>
<body>
First Name: <input type="text" id="field1" value="James ">
<br />
Last Name: <input type="text" id="field2" value="Payne">
<br /><br />
Full Name: <input type="text" id="field3">
<br /><br />
Click the button below to combine the First and Last Names<br />
The above example creates three text boxes. The first and second boxes hold a predefined value (you can delete the value and put whatever you want in the text boxes). The third box remains empty. When you click the Click Me! button it triggers the OnClick event, adding the string in the first text field to the string in the second field, resulting in: James Payne