joecool2005 Posted April 18, 2006 Share Posted April 18, 2006 Is it possible to pass a variable in Javascript to a ASP function?I want to do something like this.----------------------------------------------------------------------------------<%sub check(temp) Response.Write(temp&"<br>")end sub%><script>var varJS=123document.write("<%call check(varJS)%>")</script>----------------------------------------------------------------------------------I don't know how to pass a varJS to ASP subThxJoe Link to comment Share on other sites More sharing options...
aspnetguy Posted April 18, 2006 Share Posted April 18, 2006 try this if varJS is a number document.write('<%call check(' + varJS + ')%>') and this if it is a string document.write('<%call check("' + varJS + '")%>') Link to comment Share on other sites More sharing options...
joecool2005 Posted April 18, 2006 Author Share Posted April 18, 2006 Thank you very much Link to comment Share on other sites More sharing options...
joecool2005 Posted April 18, 2006 Author Share Posted April 18, 2006 When I do this, ----------------------------------------------------------------------------------<%sub check(temp) dim varASP varASP="abc" Response.Write(temp=varASP)end sub%><script> var varJS="abc" document.write('<%call check("'+varJS+'")%>')</script>----------------------------------------------------------------------------------Why it returns false when I compare varJS and varASP?Both of them are they string?ThxJoe Link to comment Share on other sites More sharing options...
pulpfiction Posted April 18, 2006 Share Posted April 18, 2006 try doing this, string compare, Response.Write(strcomp(temp,varASP))Returns:-1 (if string1 < string2) 0 (if string1 = string2) 1 (if string1 > string2) Null (if string1 or string2 is Null) Link to comment Share on other sites More sharing options...
joecool2005 Posted April 18, 2006 Author Share Posted April 18, 2006 Thank you for your help.It returns 1 when I do Response.Write(strcomp(temp,varASP))Do you know how to fixe it to make them equal?Thx Link to comment Share on other sites More sharing options...
pulpfiction Posted April 18, 2006 Share Posted April 18, 2006 thats wierd, i am getting a 0, try print the value of temp, use below code, the temp must be "abc"<%sub check(temp)dim varASPvarASP="abc"response.write("temp = "+temp)temp=varASPResponse.Write(strcomp(temp,varASP))end sub%> Link to comment Share on other sites More sharing options...
joecool2005 Posted April 18, 2006 Author Share Posted April 18, 2006 Ok your code returned me 0.On my code when I do thisResponse.Write("<br>"&len(temp)&"<br>"&len(varASP)) it returns 9 and 3That's strange! Link to comment Share on other sites More sharing options...
pulpfiction Posted April 18, 2006 Share Posted April 18, 2006 i am sorry, i made a big mistake.. i forgot to comment a part temp=varASPi am also getting the same error as yours.... Link to comment Share on other sites More sharing options...
vinphetamin Posted April 18, 2006 Share Posted April 18, 2006 You could do this in an asp page or html or something else: <html><head><script language="vbscript"><!-- sub check(temp) document.write("vbscript: "&temp) end sub--></script></head><body><script language="javascript"><!-- var javaVar = 10; document.write("javascript: "+javaVar+"<br />"); check(javaVar);//--></script></body></html> Link to comment Share on other sites More sharing options...
vinphetamin Posted April 18, 2006 Share Posted April 18, 2006 <%sub check(temp)dim varASPvarASP="abc"Response.Write(temp=varASP)end sub%><script>var varJS="abc"document.write('<%call check("'&varJS&'")%>')</script>I get True returned Link to comment Share on other sites More sharing options...
joecool2005 Posted April 19, 2006 Author Share Posted April 19, 2006 Thank you for your help.I tried to run your code and I got false. When I used the "len" function to verify, I got different length. It's weird!<%sub check(temp)dim varASPvarASP="abc"Response.Write(len(temp)&" "&len(varASP))end sub%><script>var varJS="abc"document.write('<%call check("'&varJS&'")%>')</script> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now