Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Output JS variables with CF

Participant ,
May 19, 2011 May 19, 2011

This is probably a simple one... But I'm not very familiar with JavaScript so I really have no idea.

How would I output the variables in this script with Coldfusion?

<SCRIPT LANGUAGE="JAVASCRIPT">
<!--
var d = new Date();
var curr_date = d.getTime();
//-->
</SCRIPT>

727
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
May 19, 2011 May 19, 2011

Yup, it is very simple, you simply CAN NOT do this.

CFML is executed by a ColdFusion Application Server, usually running on a web server.  JavaScript is executed by a browser running on a client computer.  These executions happen at completely different times on completely different systems with completely different memories with completely different variable pointers to values in those memories that can be thousands of miles apart. [And even if they ARE sharing the same system, in a development workstation for example, ColdFusion and JavaScript still CAN NOT read each others memory locations]

It is very easy, and powerful, to use CFML to generate JavaScript output to be returned to a browser, just like generating HTML, CSS, XML, etc.

It is pretty easy, and powerful, to use JavaScript to make requests to a web server for CFML resources.

But one must always keep in mind that these languages are not sharing the same computer, they are not executing at the same time and YOU are responsible in designing how they will interact over the HTTP request-response, client-server nature of Internet Applications.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 19, 2011 May 19, 2011

I take it you want to display the local time?  If so, you carry on without coldfusion.  You can use document.write(), stick the value into a div, or something else, depending on your requirement.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 19, 2011 May 19, 2011

I see.  Well that wasn't what I wanted to hear! 

Dan, I was just using that as a basic example.  What I want to do is take the variables of a JS function, insert the values into a form, then submit.  I wanted to use ColdFusion as a debugging step to see what variables are being produced by the function so I know what to insert.

So I really have a Javascript/HTML issue and wanted to use ColdFusion as a step to figure out what I was dealing with.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
May 19, 2011 May 19, 2011

idesdema wrote:

So I really have a Javascript/HTML issue and wanted to use ColdFusion as a step to figure out what I was dealing with.

Sorry, ColdFusion can't help you here.

But the firebug plugin for Firefox can.  It can give you a lot of insight into what is going on in the browser.

It is also pretty easy to just use an quick JavaScript alert() function if you need a quick one-off of a value.

<SCRIPT LANGUAGE="JAVASCRIPT">
<!--
var d = new Date();
var curr_date = d.getTime();

alert(cur_date);
//-->
</SCRIPT>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 19, 2011 May 19, 2011
What I want to do is take the variables of a JS function, insert the values into a form, then submit.  I wanted to use ColdFusion as a debugging step to see what variables are being produced by the function so I know what to insert.

Just use FireBug.

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 19, 2011 May 19, 2011
LATEST

Ok sounds like Firebug may provide some insight.  Installing now...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources