Create your own event in JavaScript
Description
The following code shows how to create your own event.
Example
<HTML>
<HEAD>
<SCRIPT>
function FormData (name, text1, text2) {
this.name = name;<!-- w w w . j a va 2 s .co m-->
this.text1 = text1;
this.text2 = text2;
}
FormData.prototype.toString = function () {
return this.name;
}
function on_Same () {
alert("The two values are the same!");
}
function check_Same() {
if (this.text1 == this.text2) {
this.onSame();
}
}
FormData.prototype.checkSame = check_Same;
FormData.prototype.onSame = on_Same;
function createFormData (name, text1, text2) {
var x = new FormData (name, text1, text2);
x.checkSame();
}
</SCRIPT>
</HEAD>
<BODY>
<FORM>
Name your object:<input type=text name="txtName">
Enter first text:<input type=text name="txtFirst">
Enter second text:<input type=text name="txtSecond">
<input type=button value="Do It!"
onClick="createFormData (txtName.value, txtFirst.value, txtSecond.value);">
</FORM>
</BODY>
</HTML>
The code above generates the following result.
Javascript Tutorial Event Basic
Add click event handler to form and check t...
Check Event bubble phase in JavaScript
Check event type in JavaScript
Demonstrate Event Capture and Bubble and ev...
Find out event handling and firing phases i...
Get element id through event object in Java...
Get event Phase in JavaScript
Get event source element name and id in Jav...
Get the event target in JavaScript
Get the event type for key event in JavaScr...
Get the event type from event in JavaScript
Get the source tag name which triggered the...
Prevent event Bubble and Capture in JavaScr...
Remove a certain type of event listener fro...
Show the event capture phase in JavaScript
Stop Event Propagation in JavaScript
Tell if the event supports bubble with Even...
Test the event bubbling in JavaScript
Add click event handler to form and check t...
Check Event bubble phase in JavaScript
Check event type in JavaScript
Create your own event in JavaScript
Demonstrate Event Bubbling in JavaScriptDemonstrate Event Capture and Bubble and ev...
Find out event handling and firing phases i...
Get element id through event object in Java...
Get event Phase in JavaScript
Get event source element name and id in Jav...
Get the event target in JavaScript
Get the event type for key event in JavaScr...
Get the event type from event in JavaScript
Get the source tag name which triggered the...
Prevent event Bubble and Capture in JavaScr...
Remove a certain type of event listener fro...
Show the event capture phase in JavaScript
Stop Event Propagation in JavaScript
Tell if the event supports bubble with Even...
Test the event bubbling in JavaScript