#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    26
    Rep Power
    0
    Hi

    I wanna pass a JS variable to ASP (VB)
    i.e. <script language="javascript">
    var tVar
    tVar = "hello"
    </script>
    <%
    dim tVar1
    %>
    i want tVar1 can use the value of the tVar

    can i do that? and how?

    Thanks!!!
  2. #2
  3. No Profile Picture
    ssvr6
    Guest
    Devshed Newbie (0 - 499 posts)
    Are these on the same page? Cause you can just pass it as a hidden field and request it from the next page using VB Script.


    Steve

    ------------------
    Web Application Developer
    steveingels@dbt.net
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    26
    Rep Power
    0
    on the same page, can i do this?
    thanks~~
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    2
    Rep Power
    0
    Looks like you are trying to mix server side code with client side, and unfortunatly this isnt possible.
    In otherwords, your ASP runs on the server, before the page is ever rendered inside a browser, while your javascript is processed during page load or after.
    So if you create a variable in client side javascript, there is no way for the server side asp to know it, since the ASP has already been processed.
    You can do as was mentioned above and have a form submit to itself with the js var in a hidden field, then grab it in the asp.

    Alternatively you CAN use an ASP var in a js script without refreshing.

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <%
    strAspVar = "this was created in ASP, and passed to javascript"
    %>
    <head>
    <script>
    function showJsVar()
    { var strJsVar = "<%=strAspVar%>"
    alert(strJsVar) }
    </script>
    </head>
    <body onLoad = "showJsVar();">
    [/code]

    apologies if code doesnt display, im guessing on the correct way to alow code to be rendered without trying to run it P
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2001
    Location
    Switzerland
    Posts
    9
    Rep Power
    0

    that's it!


    Hell that's what the last poster say, use a response.write to echo ur var's content in the javascript area.

    did u get it work?

    Gen

Similar Threads

  1. How to call JavaScript in ASP?
    By tudovich in forum JavaScript Development
    Replies: 1
    Last Post: November 21st, 2003, 03:41 PM
  2. Create/Access Cookies in ASP and Client-Side Javascript
    By greggjc in forum JavaScript Development
    Replies: 0
    Last Post: November 19th, 2003, 04:24 PM
  3. JavaScript functions & ASP forms
    By Pasiphae1213 in forum JavaScript Development
    Replies: 1
    Last Post: April 14th, 2003, 03:13 PM
  4. call asp function from javascript
    By alshawver in forum JavaScript Development
    Replies: 6
    Last Post: November 30th, 2001, 02:37 PM
  5. ASP, JavaScript and SQL
    By Geniium in forum JavaScript Development
    Replies: 1
    Last Post: June 15th, 2001, 09:42 AM

IMN logo majestic logo threadwatch logo seochat tools logo