I am trying the execute a VBscript function from an anchor
tag, but seem to be unable to get the syntax correct.
Following is a simple web page that diplays a msgbox.
It works from the button, but not from the Anchor.
Can you you help me?

<HTML>
<INPUT id="cmdWrite" onclick="vbscript:WriteFile('Hello')"
type="button" value="Write File"><BR><BR>
<A HREF="vbscript:WriteFile('Hello')">Say Hello</A>
<SCRIPT LANGUAGE=VBSCRIPT>
Sub WriteFile(Value)
Msgbox "Value=" & Value
End Sub
</SCRIPT>
</HTML>

Re: Executing vbscript function from anchor tag by Walter

Walter
Sat Aug 23 02:35:12 CDT 2003

This appears to be a bug. If you change the WriteFile Sub to a Function and
swap the single and double quotes in the <A> tag then this will work as
expected, It will also work if you leave the Sub in place and substitute the
javascript: protocol in place of the vbscript: protocol. Apparently, you
cannot call a user-defined Sub from a <A> tag using the vbscript: protocol.

"KLomax" <KLomax@Noteworld.com> wrote in message
news:05e001c368ef$b6c91610$a101280a@phx.gbl...
| I am trying the execute a VBscript function from an anchor
| tag, but seem to be unable to get the syntax correct.
| Following is a simple web page that diplays a msgbox.
| It works from the button, but not from the Anchor.
| Can you you help me?
|
| <HTML>
| <INPUT id="cmdWrite" onclick="vbscript:WriteFile('Hello')"
| type="button" value="Write File"><BR><BR>
| <A HREF="vbscript:WriteFile('Hello')">Say Hello</A>
| <SCRIPT LANGUAGE=VBSCRIPT>
| Sub WriteFile(Value)
| Msgbox "Value=" & Value
| End Sub
| </SCRIPT>
| </HTML>
|



Re: Executing vbscript function from anchor tag by Michael

Michael
Sat Aug 23 11:54:32 CDT 2003

KLomax wrote:
> I am trying the execute a VBscript function from an anchor
> tag, but seem to be unable to get the syntax correct.
> Following is a simple web page that diplays a msgbox.
> It works from the button, but not from the Anchor.
> Can you you help me?
>
> <HTML>
> <INPUT id="cmdWrite" onclick="vbscript:WriteFile('Hello')"
> type="button" value="Write File"><BR><BR>
> <A HREF="vbscript:WriteFile('Hello')">Say Hello</A>
> <SCRIPT LANGUAGE=VBSCRIPT>
> Sub WriteFile(Value)
> Msgbox "Value=" & Value
> End Sub
> </SCRIPT>
> </HTML>


<HTML>
<INPUT id="cmdWrite"
onclick='vbscript:WriteFile("Hello")'
type="button"
value="Write File">
<BR><BR>
<A HREF=""
onclick='vbscript:WriteFile("Hello")'>Say Hello
</A>
<SCRIPT LANGUAGE=VBSCRIPT>
Sub WriteFile(Value)
Msgbox "Value=" & Value
window.event.returnValue = False
End Sub
</SCRIPT>
</HTML>


--
Michael Harris
Microsoft.MVP.Scripting

Windows 2000 Scripting Guide
Microsoft® Windows®2000 Scripting Guide
http://www.microsoft.com/technet/scriptcenter/scrguide/sagsas_overview.asp

System Administration Scripting Guide - samples scripts
http://www.microsoft.com/downloads/release.asp?ReleaseID=38942

WSH 5.6 documentation download
http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en


Re: Executing vbscript function from anchor tag by Michael

Michael
Sat Aug 23 13:12:36 CDT 2003

BTW, if you are going to call a VBScript Sub (as opposed to a Function) from
an oneventname attribute, don't use ()s unless you explicitly use the Call
statement:


onclick='vbscript:WriteFile "Hello"'
or
onclick='vbscript:Call WriteFile("Hello")'


That way if you ever modify the Sub to expect more than one argument, you
won't get the infamous 'Cannot use parentheses when calling a Sub' error...


--
Michael Harris
Microsoft.MVP.Scripting

Windows 2000 Scripting Guide
Microsoft® Windows®2000 Scripting Guide
http://www.microsoft.com/technet/scriptcenter/scrguide/sagsas_overview.asp

System Administration Scripting Guide - samples scripts
http://www.microsoft.com/downloads/release.asp?ReleaseID=38942

WSH 5.6 documentation download
http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en