can run javascript can't run vbscript - WHY

Discussion in 'ASP .Net' started by duncan, Oct 9, 2004.

  1. duncan

    duncan Guest

    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
    duncan, Oct 9, 2004
    #1
    1. Advertising

  2. duncan

    Jared Guest

    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>
    "duncan" <> wrote in message
    news:...
    > 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
    Jared, Oct 9, 2004
    #2
    1. Advertising

  3. duncan

    Guest

    Re: can run javascript can

    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...
    , Oct 27, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    861
    Mark Rae
    Dec 21, 2006
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,761
    Smokey Grindel
    Dec 2, 2006
  3. Doug
    Replies:
    5
    Views:
    126
    Laurent Bugnion, GalaSoft
    Dec 5, 2003
  4. tabonni
    Replies:
    4
    Views:
    219
    kaeli
    Aug 23, 2004
  5. Replies:
    2
    Views:
    265
Loading...

Share This Page