I need to pass a variable from my JavaScript to CF. Is there anyway to do it? Any help is greatly appreciated.<br>
<br>
Thanks in advance,<br>
<br>
Brian Yager<br>
byager@logsa.army.mil
Is this from page to page or on the same template? If you are passing the variable to another page, like a forms handler, you can just put the variable in your url line or pass it as a form variable. CF can then read it using #url.myvariable# or #form.myvariable#.<br>
<br>
I don't think it would be possible to use a javascript variable on the same page, though, since CF has already done all it's processing before it hits the browser, and javascript doesn't do anything until after it hits the browser.<br>
<br>
Hope this helps....
Thanks Doug. Since I can't do what I need on the same page, how do I pass a variable to another page? I am not very familiar with Java so please bear with me. From my script, can I go straight to another page passing my variable? If so, how?. Then when I am on the other page, how do I get it into a CFSET statement. Thanks again for your help.<br>
<br>
Brian
I caught this same question in the javascript forum after I read this one. You can get the host ip address and the host name by using the Cold Fusion cgi envionment variables #CGI.REMOTE_ADDR# and #CGI.REMOTE_HOST#. This would eliminate the need to try to convert from javascript to Cold Fusion and the need for a second template.<br>
<br>
You could use these variables directly in an SQL statement to write this information to your database like this:<br>
<CFQUERY><br>
insert into mytable<br>
(ipaddress,hostname)<br>
Values (#CGI.REMOTE_ADDR#,#CGI.REMOTE_HOST#)<br>
</CFQUERY><br>
<br>
I hope this is what you are looking for. If you still need to pass the actual javascript variable to another page, place the variable name and value after a question mark like this:<br>
<br>
<br>
You will be able to get this value on the next page using the variable name #url.ipaddress#<br>
<br>
If you need to pass more than one variable, just separate them with and ampersand. (
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.