Contact US

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!

*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

Passing JavaScript Variables to CF

Passing JavaScript Variables to CF

Passing JavaScript Variables to CF

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

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

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.


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:
insert into mytable

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:


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=

RE: Passing JavaScript Variables to CF

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! Already a Member? Login

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