This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes HTML, CSS and JavaScript and the fly likes Dynamic Element Function Parameter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Dynamic Element Function Parameter" Watch "Dynamic Element Function Parameter" New topic
Author

Dynamic Element Function Parameter

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

I am creating a DIV like so:

var div = document.createElement("DIV");

and adding an onmousedown function like so

div.onmousedown = someFunction;

What I need to do though is pass an argument to someFunction. If I create it statically, it would take 2 arguments (event, id). I know that the above code passes event automatically, but how can I also pass it a string value for id?

Thanks.


GenRocket - Experts at Building Test Data
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
something like?:

= function(){someFunction(event,"id");}

Eric
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Well, I tried that before, and it says that event is not defined. What I am trying to duplicate dynamically is the following static html:

Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Something like this:



[ugh smiles!]
[ugh mistake - should work now in FF]
[ March 28, 2006: Message edited by: Eric Pascarello ]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

I get event is not defined, in FF.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Ok, well, while I await anyone's suggestions for the above solution, I have figured out a workaround. I created the DIV in HTML and set the display to none. When I need a new one, I use the cloneNode function of that div, give it a new ID and various other properties and all works well.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
It should have worked if I would have not typed it wrong....


Eric
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Perfect Eric. Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dynamic Element Function Parameter