Solved

document.onmouseup

Posted on 2009-07-03
2
635 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

777 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