The vbscript code is executed twice when I click the print button to print
some text after invoking ms word. I assume that I need to write some code so
that the code that invoke ms word, etc, would not be executed at the load
time, but execute only when the button is clicked. I am having onclick
routine in the header script tag. What could be the condition and codes I
need to put it so that vbscript would be executed only once?

Thanks
Daniel

Re: executing vbscript codes twice by Rafael

Rafael
Fri May 27 21:44:41 CDT 2005

will be easier to help if you post a copy of the code.

RT
"Daniel" <Daniel@discussions.microsoft.com> wrote in message
news:AA98AB3A-FA58-47B1-B01E-B50B34CE9A1D@microsoft.com...
> The vbscript code is executed twice when I click the print button to print
> some text after invoking ms word. I assume that I need to write some code
> so
> that the code that invoke ms word, etc, would not be executed at the load
> time, but execute only when the button is clicked. I am having onclick
> routine in the header script tag. What could be the condition and codes I
> need to put it so that vbscript would be executed only once?
>
> Thanks
> Daniel



Re: executing vbscript codes twice by Daniel

Daniel
Sat May 28 09:07:02 CDT 2005

I simplified the version enough to have the msgbox being executed twice.

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>




"Rafael T" wrote:

> will be easier to help if you post a copy of the code.
>
> RT
> "Daniel" <Daniel@discussions.microsoft.com> wrote in message
> news:AA98AB3A-FA58-47B1-B01E-B50B34CE9A1D@microsoft.com...
> > The vbscript code is executed twice when I click the print button to print
> > some text after invoking ms word. I assume that I need to write some code
> > so
> > that the code that invoke ms word, etc, would not be executed at the load
> > time, but execute only when the button is clicked. I am having onclick
> > routine in the header script tag. What could be the condition and codes I
> > need to put it so that vbscript would be executed only once?
> >
> > Thanks
> > Daniel
>
>
>

Re: executing vbscript codes twice by Monkey

Monkey
Sat May 28 09:23:29 CDT 2005

Sub window_onLoad

End Sub

This should prevent the execution of code when the page initially
opens. Then when you click the print button, you should get your
MsgBox.

Then I tested it and it still opened it twice. To make it open only
once, I changed both places from Print_onClick to Printme.

For example

<html>
<head>
<title></title>
<SCRIPT LANGUAGE="VBScript">

Sub window_onLoad

End Sub

Sub Printme
MsgBox "Hi!"
End Sub
// -->
</SCRIPT>
</head>
<FORM name="test">
<INPUT type="BUTTON" value="Print" name="Print"
onClick="Printme" >
</form>
</html>

I'm guessing it has something to do with being called onClick...

Monkey


Re: executing vbscript codes twice by Joe

Joe
Sat May 28 09:45:50 CDT 2005

Hi,

[snipped]

"Monkey" <mnreese@hotmail.com> wrote in message
news:1117290209.053978.310840@g49g2000cwa.googlegroups.com...
...
> Then I tested it and it still opened it twice. To make it open only
> once, I changed both places from Print_onClick to Printme.
...
> I'm guessing it has something to do with being called onClick...
>
> Monkey

Good experimentation catch. Alex Angelopoulos explains the cause in this
thread:

http://groups-beta.google.com/group/microsoft.public.scripting.vbscript/browse_frm/thread/4707894af5e79b7f/d7481be33b7ae82b?q=twice+group:microsoft.public.scripting.*&rnum=1&hl=en#d7481be33b7ae82b

Regards,
Joe Earnest



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.