Click to See Complete Forum and Search --> : Passing a value from server to client vice versa


Johntoel
08-25-2006, 02:56 AM
<%
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

buntine
08-25-2006, 03:48 AM
Simply use the variable you already have in scope.

<%
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.

Johntoel
08-25-2006, 04:24 AM
Hi Buntine, after trying the code I still did not get 'yes.asp?id=1'. Have you tried the code above? Thank's

russell
08-25-2006, 11:02 AM
change thisResponse.Write (" location.href = 'yes.asp?id1='&myVar" & ";" & vbcrlf) to thisResponse.Write ("location.href = 'yes.asp?id1=' + myVar" & ";" & vbcrlf)

lmf232s
08-25-2006, 12:14 PM
I believe what you want is this

Response.Write ("location.href = 'yes.asp?id1=" & myVar & "';" & vbcrlf)

This will display

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

Johntoel
08-26-2006, 10:48 PM
Thank's Russell and lmf232s, the code works.