By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,814 Members | 2,162 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,814 IT Pros & Developers. It's quick & easy.

Setting onmousedown as a property value

P: n/a
Hi All,

Is there a way to access the value assigned to onmousedown for an
object? I've been searching online but can only seem to find how it is
assigned via html. What I need to do is access the value (the script
string) in javascript.

For example, I'd like to try to do something like this:

function virtualClick(objectName) {
eval(document.getElementById(objectName).onmousedo wn);
}

I am of course not explaining the full problem in detail, but would
appreciate any input on how to access the onmousedown value (or to know
if it even exists as a property).

Thank you,

Walker

Sep 12 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a


walkerfx wrote:

function virtualClick(objectName) {
eval(document.getElementById(objectName).onmousedo wn);
If you want to call the event handler then do that e.g.
var element = document.getElementById(objectName);
if (element != null && element.onmousedown != null) {
element.onmousedown();
}
The event handler (if it is set) is a function property and you simply
call that as shown and not with using eval.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 12 '06 #2

P: n/a
element.onmousedown();

Thanks Martin, this worked great!

Sep 12 '06 #3

P: n/a
ASM
walkerfx a écrit :
Is there a way to access the value assigned to onmousedown for an
object? I've been searching online but can only seem to find how it is
assigned via html. What I need to do is access the value (the script
string) in javascript.

For example, I'd like to try to do something like this:

function virtualClick(objectName) {
eval(document.getElementById(objectName).onmousedo wn);
}
function virtualClick(objectId) { // and NOT object_NAME

alert(document.getElementById(objectId).getAttribu te('onmousedown'));
}
I am of course not explaining the full problem in detail, but would
appreciate any input on how to access the onmousedown value (or to know
if it even exists as a property).
<html>
<head>
<script type="text/javascript">
function tellMe(e) {
e = e.target? e.target : e.srcElement;
if(e.getAttribute('onmouseover'))
alert(e.getAttribute('onmouseover'));
else alert('no');
}
</script>
</head>
<body onmousedown="tellMe(event)">
<p id=ici
onmouseover="x = this.innerHTML; this.innerHTML='What's matter ?';"
onmouseout="this.innerHTML=x;">
hello
</p>
</body>
</html>
--
Stephane Moriaux et son [moins] vieux Mac
Sep 12 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.