Re: executing vbscript codes twice by Michael
Michael
Sat May 28 15:38:36 CDT 2005
Daniel wrote:
> I simplified the version enough to have the msgbox being executed
> twice.
Because the onclick event for the object named 'Button' is being connected
to the same handler twice...
In client side VBScript, sub/functions with names in the form
objectname_eventname automatically connect the object's event to the handler
for you based entirely on the sub/function name. That's the implicit
connection.
You are also coding onClick="Print_onClick" to connect the event to the
handler. That's the explicit connection.
Either (A) change the handler's name and the onclick attribute assignment to
avoid the duplication (e.g., Sub PrintOnClick and onclick="PrintOnClick ")
or (B) drop the explicit onClick="Print_onClick" attribte assignment.
For clarity, I prefer explicit over implicit connections, so...
Sub PrintOnClick
...
End Sub
and ...
onclick="vbscript:Call PrintOnClick()"
is the way *I* would code this.
>
> Thanks
> Daniel
>
> <html>
> <head>
> <title></title>
> <SCRIPT LANGUAGE="VBScript">
> <!--
> Sub Print_onClick
> MsgBox "Hi!"
> End Sub
> // -->
> </SCRIPT>
> </head>
> <FORM name="test">
> <INPUT type="BUTTON" value="Print" name="Print"
> onClick="Print_onClick" > </form>
> </html>
--
Michael Harris
Microsoft MVP Scripting
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Please ask follow-up questions via the original newsgroup thread.