Solved

document.onmouseup

Posted on 2009-07-03
2
632 Views
Last Modified: 2013-11-19
Hi

I am defining an event using javascript

like

document.onmouseup = mousehandler;

but now I want to define another event on onmouseup. How can I do that
0
Comment
Question by:KaranGupta
2 Comments
 
LVL 5

Accepted Solution

by:
Opalelement earned 500 total points
ID: 24772580
Snippet:)
document.onmouseup = runMouseEvents;
 

function runMouseEvents()

{

    mousehandler();

    anotherEvent();

}
 

function mousehandler()

{

    // code

}
 

function anotherEvent()

{

    // other event code

}

Open in new window

0
 
LVL 3

Expert Comment

by:laneway
ID: 24773625
You can also define an unlimited number of events like this:
<input id="btn" type="button" value="I have two events!" />

<script>

// define event functions

function event_one() { alert('one!'); }

function event_two() { alert('two!'); }

// get the button element that will trigger these events

var btn = document.getElementById('btn');

// attach the two events for internet explorer

if (btn.attachEvent) { 

  btn.attachEvent('onclick',event_one); 

  btn.attachEvent('onclick',event_two); 

}

// attach the two events for all other browsers

if (btn.addEventListener) { 

  btn.addEventListener('click',event_one,false); 

  btn.addEventListener('click',event_two,false); 

}

</script>

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now