Event listener in JavaScript with example

Event listener in JavaScript with example

What is event listener in JavaScript? Can anyone please post an example of Event listener??

Thanks in Advance!!

View Answers

December 11, 2012 at 9:34 PM

<html>
  <head>
  <title> Add Event Listener Example </title>

</head>
<body onload="init()">
</body>

December 11, 2012 at 9:39 PM

    <html>
     <head>
        <script type="text/javascript">
            function OnButtonDown (button) {
                button.style.color = "#ff0000";
            }
            function OnButtonUp (button) {
                button.style.color = "#000000";
            }

            function Init () {
                var button = document.getElementById
                              ("testButton");
                if (button.addEventListener) {  
                   button.addEventListener ("mousedown",                       
                    function () {OnButtonDown (button)}, false);

                   button.addEventListener ("mouseup", 
                    function () {OnButtonUp (button)}, false);
                }
                else {
                 if (button.attachEvent) {   version 9
                   button.attachEvent ("onmousedown", 
                    function () {OnButtonDown (button)});
                   button.attachEvent ("onmouseup", 
                    function () {OnButtonUp (button)});
                 }
               }
            }
        </script>
     </head>
     <body onload="Init ()">
        Click on the following button and see its text color.
        <br />
        <button id="testButton">Test button</button>
     </body>
    </html>

    Here we are adding two event listeners 
    1.mouseup

December 11, 2012 at 9:39 PM

<html>
 <head>
    <script type="text/javascript">
        function OnButtonDown (button) {
            button.style.color = "#ff0000";
        }
        function OnButtonUp (button) {
            button.style.color = "#000000";
        }

        function Init () {
            var button = document.getElementById
                          ("testButton");
            if (button.addEventListener) {  
               button.addEventListener ("mousedown",                       
                function () {OnButtonDown (button)}, false);

               button.addEventListener ("mouseup", 
                function () {OnButtonUp (button)}, false);
            }
            else {
             if (button.attachEvent) {   version 9
               button.attachEvent ("onmousedown", 
                function () {OnButtonDown (button)});
               button.attachEvent ("onmouseup", 
                function () {OnButtonUp (button)});
             }
           }
        }
    </script>
 </head>
 <body onload="Init ()">
    Click on the following button and see its text color.
    <br />
    <button id="testButton">Test button</button>
 </body>
</html>

Here we are adding two event listeners 
    1.mouseup

September 27, 2011 at 12:49 PM

What is an Event Handling?

An Event - basically, an action or activity that goes on between the user and the application. In Java programming, In Java, Abstract Windowing Toolkit (AWT) handles such class and returns appropriate response to the user.

Event handling Is a method that understands the event and processes it.

Setting an even on button click

<html>

    <script language="JavaScript">
    <!--
    function clickFirstButton()
    {
      document.myForm.button1.click();
    }
    -->
    </script>
    <form name="myForm">
      <input type="button"
             value="Display alert box"
             name="button1"
             onClick="alert('You clicked the first button.')"><br>
      <input type="button"
             value="Call on button 1"
             name="button2"
             onClick="clickFirstButton()">
    </form>    
    </html>

Event Handling in Java AWT Example









Related Tutorials/Questions & Answers:
Event listener in JavaScript with example
Event listener in JavaScript with example  What is event listener in JavaScript? Can anyone please post an example of Event listener?? Thanks in Advance
Java event-listener
Java event-listener  What is the relationship between an event-listener interface and an event-adapter class
Advertisements
Flex Add Event Listener example
in the example we have two event listener Handler and Handler1 respectively... in flex components. Here in the example only mouse event is added... Flex addEventListener example   
Flex Remove Event Listener example
. In the example method doesn't able to remove the event from the button with id b3... Flex removeEventListener example       In the example below flex
javascript event handling examples
javascript event handling examples  javascript event handling examples   var handleClick = function(e) { // Older IEs set the `event...; // For example's sake. if (target.tagName.toLowerCase() == 'a' && target.className
Action Event Listener
Action Event Listener   ... listener for the component but second way permits you to include more than one event listeners. 1. Using "actionListener" attribute of the component
JavaScript onkeypress event
JavaScript onkeypress event...; This section illustrates you the use of onkeypress event in JavaScript. In the given example, we are going to show you how to restrict the user to enter any
JavaScript Key Event
JavaScript onkeyup Event...; This section illustrates you the use of onkeyup event in JavaScript. In the given example, we are going to show you how to display the text of textField1
Flex adding single event on varied components Example
the pop-up windows. So with this example a clear idea for adding single event... Flex single event on varied components       In the example below, listeners for a single
Value Change Event Listener
Value Change Event Listener   ... to use only one listener for the component but second way permits you to include... by this listener occurs. So processValueChange() method should be implemented
javascript recursion example
javascript recursion example   javascript recursion example   <html> <script> function factorial (n) { if(n==0) return(1); return (n * factorial (n-1) ); } document.write(factorial(5)); <
Need an Example of calendar event in java
Need an Example of calendar event in java  can somebody give me an example of calendar event of java
Java - Event Listeners Example in Java Applet
Java - Event Listeners Example in Java Applet  ... on the several objects. In this example you will see that how to use the event listener and to perform appropriate tasks. In this example the 
JavaScript google map API example.
JavaScript google map API example.  How to Use Google Maps API in JavaScript?   Google Maps- A map is a way of representation of your route.... Initially Google introduced JavaScript maps API.Here is one example- <html>
Flex terminating event flow example
Flex terminating event flow example       In the example below, how to terminate an event flow is demonstrated. With this example the motive of previous event phase detecting
Browser Back Button click event javascript
Browser Back Button click event javascript  I am using the below code but window.onBeforeUnload is not working with back button.. how can i apply the below code for the click event of back button? window.onBeforeUnload
Event Adapters
the implementation of all the methods of the listener interface. The following example... Event Adapters       There are some event listeners that have multiple methods to implement
Java listener
Java listener  What is source and listener
JavaScript onkeyup event
JavaScript onkeyup event This section illustrates you the onkeyup event. It occurs when the user releases a key from its depressed position. Here we have created two textboxes. As the user user enter the text in first textbox, the same
Javascript
Javascript  How validations are done using javascript ,with example? and interview questions on javASCRIPT
Flex event phase detection example
Flex event phase detection example   ... regarding an event, such as detecting the event listener for handling.... In the example, event current phase is detected inside different TextInput controls
httpsession listener - JSP-Servlet
httpsession listener  i want to see the example of httpsession listener where it is counting how many times the session has been created
Event in flex
of the Event class can be used in event listener functions to affect the behavior of the event object. Some events have an associated default behavior. For example... the word under the mouse pointer at the time of the event. Your event listener can
JavaScript array reverse example
JavaScript array reverse example       JavaScript Array class have one method reverse() which... as follows: arrayname.reverse()ADS_TO_REPLACE_1 In this example we have created an array
@WebListener Annotation Servlet Example
to implement a listener interface in servlet. In this example I will use...@WebListener Annotation Servlet Example In this tutorial you will learn what the difference is in the implementation of listener in servlet in older version
Flex dispatch event example
value, boolean value);  Example for event_type used in the method... Flex dispatchEvent example       The example below demonstrates the working of flex
Event listeners in mxml
Event listeners in mxml  hi.. just tell me about How do you add event listeners in mxml components. Now AS3 components? Please give an example in both MXML and AS3 Thanks  Ans: There are some function
JavaScript
JavaScript  clone JavaScript
ModuleNotFoundError: No module named 'listener'
ModuleNotFoundError: No module named 'listener'  Hi, My Python... 'listener' How to remove the ModuleNotFoundError: No module named 'listener... to install padas library. You can install listener python with following
Listener ports - JMS
Listener ports  I am getting the following error on my server. Please...] 00000150 MDBListenerIm I WMSG0043I: MDB Listener CLSMGUncorrelatedMDBListenerPortA...:25:392 CST] 000000b8 MDBListenerIm I WMSG0042I: MDB Listener
Listener ports - JMS
Listener ports Error in JMS  Hi, I am getting an listener ports error in JMS. Does anyone have solution
Javascript Form validation Example
Javascript Form validation Example In this section we will discuss about how to validate your application form in javascript. In many applications data... am giving a simple example for form validation using Javascript. ExampleADS
JavaScript createEventObject method
with the help of JavaScript. We can create an event object by using the JavaScript... language="JavaScript"> function first() { var event... JavaScript createEventObject method   
dynamically add listener to a SWT widget
dynamically add listener to a SWT widget  hello, I am using SWT... as we do in gmail,and there should be a listener for every link.here is the code...;"); attachLink.addListener(SWT.Selection, new Listener() { public void handleEvent
javascript
javascript  javascript code to dynamically add table on button click.../javascript/javascriptexamples/javascript-add-row-dynamically.shtml http://www.roseindia.net/javascript/javascript-add-row-to-table.shtml http://www.roseindia.net
JavaScript cloneNode example
JavaScript cloneNode example   .... JavaScript cloneNode() method creates a clone copy of the given node object.... Description of code: In our example code for creating a clone of given node object
J2ME Event Handling Example
J2ME Event Handling Example       In J2ME programming language, Event Handling are used to handle certain... event like selecting an item from a listADS_TO_REPLACE_1 And low level events like
javascript
javascript  Hi deepak, how to write form validation on javascript
JavaScript
should use JavaScript? Thanks   Hi, JavaScript is scripting language that runs on browser. You have to embed JavaScript in HTML page. Please see JavaScript tutorial. Thanks
JavaScript
JavaScript  how to get full path of a file type in javascript
javascript
javascript  write a program to display implement about browsers using javascript
javaScript
javaScript  How to open a browser window that cannot be resized? (HTML + Javascript
javascript
javascript  i have just learned javascript... can you tell me what kind of applications can be made by javascript?? thank you
Java Printer Listener - Java Beginners
Java Printer Listener  I want some programs to make listener for all... for more information. http://www.roseindia.net/java/example/java/swing... for java applications i want printer listener for all applications in the system
javascript
javascript  how to set the request or session attribute in javascript head part of jsp page
javascript
javascript  Hi sir, This is sinduri, i want to learn javascript, so plz can u help me.how to learn
javascript
javascript  hi sir, if i want to learn javascript. what concepts i want to know
JAVASCRIPT
JAVASCRIPT  I have one textbox and I want to validate that it must start with number(1-0). can anyone tell me a javascript for that ? thanks in advance
Javascript
Javascript   Javascript to check Numeric entry in checkbox.....   Hi Please find the following code for numeric entry validation in javascript function validateBox(){ var data=document.myForm.someText.value
Event Handling In Java
that happens and your application behaves according to that event. For example... ) generates an event. This event is handled by the listener. Event listener listens... components has its own listener that handles the event generated by the component

Ads