passing ASP variable to JScript...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bfritz20
    New Member
    • Mar 2008
    • 1

    passing ASP variable to JScript...

    this is the only method I found for splitting a QueryString in ASP... but now I need to use that variable/string in my JavaScript function... thanks

    Code:
    <%
    Dim imdbLink
    ID = Request.QueryString("u")
    ID_split = Split(ID, "/title/")
    imdbLink = ID_split(1)
    %>
    
    <script language="javascript" runat="server">
    var theLink = imdbLink;
    ...
    </script>
    please note this is ServerSide JavaScript... so var imdbLink = "<%= imdbLink %>"; won't work. thanks
  • jeffstl
    Recognized Expert Contributor
    • Feb 2008
    • 432

    #2
    You will have to pass the variable to javascript on an event.

    That is the only way because the javascript executes locally on the users machine, the value of the variable will have to be already established on the output page. (In other words the javascript is only going to be able to work with variables on the local page, not the asp page that runs on the server)

    So some local events you could use to pass your variable is
    - onload in the body tag <body onload="MyJavaF unc(myvar)">
    - onclick on a link on the page

    Given what it looks like you are trying to do you will probably need to run your javascript onload in the body tag.

    Comment

    • jeffstl
      Recognized Expert Contributor
      • Feb 2008
      • 432

      #3
      Originally posted by jeffstl
      You will have to pass the variable to javascript on an event.

      That is the only way because the javascript executes locally on the users machine, the value of the variable will have to be already established on the output page. (In other words the javascript is only going to be able to work with variables on the local page, not the asp page that runs on the server)

      So some local events you could use to pass your variable is
      - onload in the body tag <body onload="MyJavaF unc(myvar)">
      - onclick on a link on the page

      Given what it looks like you are trying to do you will probably need to run your javascript onload in the body tag.
      OK, you specified you are using server side js. If that is the case I really don't know as typically I use javascript for local stuff. I don't know what order a page is rendered in when you are running both js and asp to generate a page.

      If the js is running first, then asp, obviously it cant be done. If asp runs first then js this method you posted "should" work. Experts?......h eh

      Comment

      Working...