can run javascript can't run vbscript - WHY

D

duncan

why does this work :-

<HEAD>
......
<SCRIPT LANGUAGE="javascript">
function test()
{
alert("test 1")
}
</SCRIPT>
.....
</HEAD>
<BODY>
....
<A HREF="JavaScript:test">test</A>
......
</BODY>

but this does not :-

<HEAD>
......
<SCRIPT LANGUAGE="vbscript">
function test()
msgbox("VB Test")
end function
</SCRIPT>
......
</HEAD>
......
<BODY>
....
<A HREF="vbscript:test">test</A>
....
</BODY>

As you can see the only real difference is I have changed JavaScript
to be vbscript and this is the problem. I don't even get a script
error reported by IE6 when I try to run the VB version. I tried
varying vbscript eg vb, vbs but nothing happens.

Why can I not run my vb function just like I can Javascript. It
defies logic (or at least mine!! which says a simple name change
should not cause this problem)

What I am trying to achieve is to run my actual code as a client side
script - with NO postback. I have managed to run some JavaScript
without causing a post back using the <A>...</A> and I can run my vb
actual code from a <ASP:BUTTON> but this causes a postback. I want
to use vb/vbscript as I am familiar with vb and want to get my pages
working asap.

One very frusttrated newbie (to ASP.NET / VB.NET)


Duncan
 
J

Jared

The alert method is part of the document object model; it has nothing to do
with javascript. Try to use the alert method in your vbscript code block

<Script language="vbscript">
Function test()
alert("VB Test")
End Function
</Script>
 
A

abc

At http://telecom.fit.edu/cfdocs/htmlreference/htmlibAttaching_Scripts.html

you can find :

Scripting as a URL

As mentioned in the first paragraph, script events can also be included as URL's. For example :


<A HREF="javascript:alert('You can never have enough examples')">This is the link text</A>

NOTE : At the time of writing, only JavaScript was supported using this method. It works in both Netscape and Internet Explorer. Future versions of Internet Explorer will include support for a <A HREF="vbscript:...."> syntax.

However, Internet Explorer allows for cross-language referencing. You can use the above construct to call a scripting function, which can be a Visual Basic Script function. For example :


<A HREF="javascript:Exec_function()">This is the link text</A>

<SCRIPT LANGUAGE="VBScript">

<!--

Sub Exec_function

Alert "You executed a Visual Basic Script function called from a JavaScript reference"

End Sub

-->

</SCRIPT>

As you will see further in this scripting reference section, the anchor (<A>) element also supports various events using the above methods. This allows scripting to be combined with hypertext links, so that the link is not exclusively executing a script.



**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top