×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Passing JavaScript Variables to CF

Passing JavaScript Variables to CF

Passing JavaScript Variables to CF

(OP)
I need to pass a variable from my JavaScript to CF. Is there anyway to do it? Any help is greatly appreciated.

Thanks in advance,

Brian Yager
byager@logsa.army.mil

RE: Passing JavaScript Variables to CF

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

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.

Hope this helps....

RE: Passing JavaScript Variables to CF

(OP)
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.

Brian

RE: Passing JavaScript Variables to CF

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.

You could use these variables directly in an SQL statement to write this information to your database like this:
<CFQUERY>
insert into mytable
(ipaddress,hostname)
Values (#CGI.REMOTE_ADDR#,#CGI.REMOTE_HOST#)
</CFQUERY>

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:

http://www.mysite.com/mytemplate.cfm?ipaddress=000.000.000.000

You will be able to get this value on the next page using the variable name #url.ipaddress#

If you need to pass more than one variable, just separate them with and ampersand. (http://www.mysite.com/mytemplate.cfm?ipaddress=000.000.000.000&hostname=yoursite.com)

RE: Passing JavaScript Variables to CF

(OP)
That is exactly what I needed. Thank you very much.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close