Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing JavaScript Variables to CF

Status
Not open for further replies.

Byager

Programmer
Oct 14, 1998
10
US
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>
&lt;CFQUERY&gt;<br>
insert into mytable<br>
(ipaddress,hostname)<br>
Values (#CGI.REMOTE_ADDR#,#CGI.REMOTE_HOST#)<br>
&lt;/CFQUERY&gt;<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. (
 
That is exactly what I needed. Thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top