Mix vbScript with JavaScript

asp , java United States
  • 18 years ago

    can i use a variable i have in vbscript in my javascript??



    something like:



    <%
    Dim strVariable
    StrVariable = ~{!0~}Hello World!~{!1~}
    %>


    on Javascript:


    var strValue
    strValue = <%strVariable%>




    thanx.

  • 18 years ago

    i dont think so, cos they'll be using different script engine doo darrs to run etc. etc.


    what I'd do (if it's all on the client side) would be to get vbscript to put the variable in a hidden text box, then get js to look at that...



    BUTTT.... why are you using both at once?!

  • 18 years ago

    ummmm i'd like to disagree with that thanks eddie...


    Code:

    <%@ LANGUAGE="VBSCRIPT" %>
    <%
    '[============= ASP Source File =============]
    '
    ' Developed with WebSoftware HotHTML 3 Professional  
    '    v0.6.568 Beta 1c
    '
    ' AUTHOR: Thushan Fernando ,
    ' DATE: 9/12/2002
    ' TIME: 6:34:57 PM
    ' COMPUTER: WEBSOFTWARE
    '
    ' COMMENTS:
    '
    '[===========================================]
    dim strTemp
    strTemp = "assaAS"
    %>
    <HTML>
    <HEAD>
    <META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
    <META NAME="GENERATOR" Content="WebSoftware Systems HotHTML 3 Professional">
    <META NAME="HotHTML3.Version" Content="v0.6.568 Beta 1c">
    <META name="COPYRIGHT" content="Copyright (c) 2002 Thushan Fernando">
    <TITLE><!-- Insert Title Here --></TITLE>
    </HEAD>
    <BODY>
    <script language="vbscript">
    dim sr
    sr = "<%=strtemp%>"
    msgbox sr
    </script>
    <!-- Insert HTML Here -->


    </BODY>
    </HTML>



    Is that what your after? and yeah why use it both at once? better off sticking with only one

  • 18 years ago

    or alternatively.... add this somewhere to get teh JavaScript output:


    Code:
    <script language="javascript">
    alert('<%=strtemp%>');
    </script>


    Thats about it...

  • 18 years ago

    yes you can mix script languages in one single ASP page, the question is if you want it to be available on server or client side.
    Here is an example to mix languages on SERVER SIDE:




    <%@ Language=VBScript %>


    <script language=JavaScript runat=server>
     function GetNameFromJavaScript(){
       return "John";
     }


    </script>


    <%
     Dim strName
      strName = GetNameFromVBScript
    %>



    The thing here is that in your <script> tag you add "runat" attribute.



    Here is an example to mix languages on CLIENT SIDE:



    <%@ Language=VBScript %>


    <%
     Dim strName
      strName = "Jason"
    %>


    <script language=JavaScript runat=server>
     function GetNameFromJavaScript(){
       var strName = "<%= strName %>";
     }


    </script>





  • 18 years ago

    Thank you all, what i tried to do was i belive a little complicated but now 10x to you it is figured!

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“If Java had true garbage collection, most programs would delete themselves upon execution.” - Robert Sewell