Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.


Assign onmouseover event programmatically?

Assign onmouseover event programmatically?

I have a field on my html page for which I want to programmatically add an onmouseover event when the user clicks a button.  I thought the following would work, but it doesn't.  What am I doing wrong?

Note the CreateMouseOver sub is called via the onclick event of the button.


Sub CreateMouseOver()

    ctl.onmouseover = "TestMe()"

End Sub

Sub TestMe()

    MsgBox "Here i yam"

End Sub

RE: Assign onmouseover event programmatically?

> ctl.onmouseover = "TestMe()"
set ctl.onmouseover = getref("TestMe");

RE: Assign onmouseover event programmatically?

No semi-colon of course.
    set ctl.onmouseover = getref("TestMe")

RE: Assign onmouseover event programmatically?

Works great, but...

I forgot to mention that I need to pass 2 arguments: a string, and and integer number

What would the syntax look like?

RE: Assign onmouseover event programmatically?

Make all the argument to the attributes of the control. The reason is that the event model exposes the srcElement which will be acting as the vehicle. I know you most probably is on some form not in html page, but in html page it is like this.

<script language="vbscript">
sub x(a,b)
    msgbox a & vbcrlf & b
end sub

sub xx    'mimic x
    msgbox a & vbcrlf & b
end sub
sub setup
    set oelem=document.getElementById("btnid")
    oelem.setAttribute "a","arga"
    oelem.setAttribute "b","argb"
    set oelem.onclick=getRef("x")
end sub
set window.onload=getRef("setup")
<button id="btnid">clickme</button>

RE: Assign onmouseover event programmatically?

There is a typo or whatever. I meant the corresponding line should be read xx rather than x.
    set oelem.onclick=getRef("xx")

RE: Assign onmouseover event programmatically?

Looks good.  Thanks.  I haven't had a chance to try your new suggestion, but will this evening.  Thanks again for your time.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close