Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > assigning to onmousedown a function that accepts an argument

Reply
Thread Tools

assigning to onmousedown a function that accepts an argument

 
 
Assaf Lavie
Guest
Posts: n/a
 
      05-06-2007
I'm creating a HTML element dynamically using javascript and I want to
assign a handler to its onmousedown.
var myNewElem;
....
myNewElem = function() { do_somthing(); }

The handler needs to be able to process the event argument that is
passed to it. i.e. the actual handler should look like this:
function mouseDownHandler(e)
{
// use e.event_details_etc
}

How do I do this?
myNewElem = function(e) { alert(e); }
doesn't seem to work. it just says 'e' is undefined.

 
Reply With Quote
 
 
 
 
scripts.contact
Guest
Posts: n/a
 
      05-06-2007
On May 6, 6:54 am, Assaf Lavie <(E-Mail Removed)> wrote:
> I'm creating a HTML element dynamically using javascript and I want to
> assign a handler to its onmousedown.
> var myNewElem;
> ...
> myNewElem = function() { do_somthing(); }


myelem.onmousedown=function(e){doSomething(e||even t)}

function doSomething(e){
alert(e)
}

works in ie,ff,op

 
Reply With Quote
 
 
 
 
Assaf Lavie
Guest
Posts: n/a
 
      05-08-2007
On May 6, 4:40 pm, "scripts.contact" <(E-Mail Removed)>
wrote:
> On May 6, 6:54 am, Assaf Lavie <(E-Mail Removed)> wrote:
>
> > I'm creating a HTML element dynamically using javascript and I want to
> > assign a handler to its onmousedown.
> > var myNewElem;
> > ...
> > myNewElem = function() { do_somthing(); }

>
> myelem.onmousedown=function(e){doSomething(e||even t)}
>
> function doSomething(e){
> alert(e)
>
> }
>
> works in ie,ff,op


Tried it and the argument is always undefined (e or event)...

 
Reply With Quote
 
scripts.contact
Guest
Posts: n/a
 
      05-08-2007
On May 8, 2:50 am, Assaf Lavie <(E-Mail Removed)> wrote:
> > > I'm creating a HTML element dynamically using javascript and I want to
> > > assign a handler to its onmousedown.

....
> Tried it and the argument is always undefined (e or event)...


Try:


[element].onmousedown=x

function x(e){
alert((e||event).clientX)
}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
Variable argument function as a parameter of a variable argument function AikidoGuy C Programming 11 11-21-2011 10:43 PM
function argument dependent on another function argument? Reckoner Python 11 01-19-2009 03:31 AM
Very useful... 'break' accepts an argument Tom Agnew Ruby 3 10-31-2005 01:45 AM
Passing in a OnMouseDown/OnMouseUp event handler as a parameter of a function Kyzer C++ 2 05-06-2005 12:53 AM



Advertisments