Passing VB to javascript

Discussion in 'ASP General' started by Ruskin, Apr 2, 2004.

  1. Ruskin

    Ruskin Guest

    I have seen a couple of web sites that detail how to do this, but seem to be
    overlooking the obvious.... I have the following code and have tried
    variations to get it working;


    <!--#INCLUDE FILE="CommonFunctions.inc"-->
    <%
    'following is vb script....
    if not MyFunction(check_field) then 'This function is in the
    include
    DisplayError("this failed")
    else
    ContinueProcess 'This sub routine is
    in the include
    end if

    sub DisplayError(iErr)
    %>
    <SCRIPT language="javascript">
    alert( <%= iErr %>);
    history.go(-1);
    </SCRIPT>
    <%
    end sub

    %>

    I want to pass different messages to the displayerror function, but just
    can't seem to make it work... Any ideas?
    Ruskin, Apr 2, 2004
    #1
    1. Advertising

  2. You're going to have to think about it slightly differently. The main
    reason is you think all of this script interacts, when in fact, first the
    ASP runs, then the client-side script runs. Let's look at it this way:

    <%
    sub showError(iErr)
    response.write "<script>" & vbCrLf & _
    "alert('" & replace(iErr,"'","\'") & "');" & _
    "history.go(-1);" & vbCrLf & _
    "</script>"
    response.end
    end sub

    ' play with making something true
    ' and somethingElse true

    something = false
    somethingElse = false

    if something then
    showError "this failed"
    end if

    if somethingElse then
    showError "that failed"
    end if
    %>

    --
    Aaron Bertrand
    SQL Server MVP
    http://www.aspfaq.com/


    "Ruskin" <> wrote in message
    news:TC4bc.2418$d%...
    >I have seen a couple of web sites that detail how to do this, but seem to
    >be
    > overlooking the obvious.... I have the following code and have tried
    > variations to get it working;
    >
    >
    > <!--#INCLUDE FILE="CommonFunctions.inc"-->
    > <%
    > 'following is vb script....
    > if not MyFunction(check_field) then 'This function is in the
    > include
    > DisplayError("this failed")
    > else
    > ContinueProcess 'This sub routine is
    > in the include
    > end if
    >
    > sub DisplayError(iErr)
    > %>
    > <SCRIPT language="javascript">
    > alert( <%= iErr %>);
    > history.go(-1);
    > </SCRIPT>
    > <%
    > end sub
    >
    > %>
    >
    > I want to pass different messages to the displayerror function, but just
    > can't seem to make it work... Any ideas?
    >
    >
    Aaron Bertrand [MVP], Apr 2, 2004
    #2
    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. Alfredo Magallón Arbizu

    Passing data to use with client javascript

    Alfredo Magallón Arbizu, Nov 20, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    425
    Alex Papadimoulis
    Nov 20, 2003
  2. Victor Bazarov
    Replies:
    25
    Views:
    845
    E. Robert Tisdale
    Mar 23, 2005
  3. pereges
    Replies:
    7
    Views:
    421
    pereges
    Jun 1, 2008
  4. Ramon F Herrera
    Replies:
    8
    Views:
    467
    Pascal J. Bourguignon
    Sep 13, 2009
  5. deadpickle
    Replies:
    1
    Views:
    951
    Jens Thoms Toerring
    Nov 7, 2010
Loading...

Share This Page