Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assign onmouseover event programmatically? 1

Status
Not open for further replies.

FancyPrairie

Programmer
Oct 16, 2001
2,917
US
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.
Code:
Sub CreateMouseOver()

    ctl.onmouseover = "TestMe()"

End Sub

Sub TestMe()

    MsgBox "Here i yam"

End Sub
 
> ctl.onmouseover = "TestMe()"
[tt]set ctl.onmouseover = getref("TestMe");[/tt]
 
Correction
No semi-colon of course.
[tt] set ctl.onmouseover = getref("TestMe")[highlight] [/highlight][/tt]
 
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?
 
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.
[tt]
<html>
<head>
<script language="vbscript">
sub x(a,b)
msgbox a & vbcrlf & b
end sub

sub xx 'mimic x
a=window.event.srcelement.a
b=window.event.srcelement.b
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")
</script>
</head>
<body>
<button id="btnid">clickme</button>
</body>
</html>
[/tt]
 
Amendment
There is a typo or whatever. I meant the corresponding line should be read xx rather than x.
[tt] set oelem.onclick=getRef("x[red]x[/red]")[/tt]
 
Looks good. Thanks. I haven't had a chance to try your new suggestion, but will this evening. Thanks again for your time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top