www.webdeveloper.com
Results 1 to 6 of 6

Thread: Passing a value from server to client vice versa

  1. #1
    Join Date
    Aug 2006
    Posts
    11

    Question Passing a value from server to client vice versa

    <%
    dim m
    m=1
    if m <> 0 then
    Response.Write ("<script type=""text/javascript"" language=""javascript"">" & vbcrlf)
    Response.Write (" var myVar =" & m & "; //use a server-side statement to pull" & vbcrlf)
    Response.Write (" alert(myVar)" & ";" & vbcrlf)
    Response.Write (" location.href = 'yes.asp?id1='&myVar" & ";" & vbcrlf)
    Response.Write ("</script>" & vbcrlf)
    end if
    %>

    I can pass the value of m to client's myVar and alert box shows it, but I am unable to assign the value of myVar into id1 so that the redirected page would be 'yes.asp?id1=1' as I need to pass querystring id1 for processing in yes.asp. Can anyone help? Thank's

  2. #2
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    5,298
    Simply use the variable you already have in scope.
    Code:
    <%
    Dim m : m = 1
    If ( m <> 0 ) Then
       Response.Write ("<script type=""text/javascript"" language=""javascript"">" & vbcrlf)
       Response.Write (" var myVar =" & m & "; //use a server-side statement to pull" & vbcrlf)
       Response.Write (" alert(myVar);" & vbcrlf)
       Response.Write (" location.href = 'yes.asp?id1='" & m & "';" & vbcrlf)
       Response.Write ("</script>" & vbcrlf)
    End If
    %>
    Keep in mind that ASP and JavaScript are two different mediums and connot explicitely communicate in such ways.

    Cheers.

  3. #3
    Join Date
    Aug 2006
    Posts
    11
    Hi Buntine, after trying the code I still did not get 'yes.asp?id=1'. Have you tried the code above? Thank's

  4. #4
    Join Date
    Feb 2003
    Posts
    2,745
    change this
    Response.Write (" location.href = 'yes.asp?id1='&myVar" & ";" & vbcrlf)
    to this
    Code:
    Response.Write ("location.href = 'yes.asp?id1=' + myVar" & ";" & vbcrlf)

  5. #5
    Join Date
    Jun 2004
    Location
    Kansas City, MO
    Posts
    1,607
    I believe what you want is this
    Code:
    Response.Write ("location.href = 'yes.asp?id1=" & myVar & "';" & vbcrlf)
    This will display

    location.href = 'yes.asp?id1=22';

  6. #6
    Join Date
    Aug 2006
    Posts
    11

    Passing a value from server to client

    Thank's Russell and lmf232s, the code works.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles