homeservicesportfoliocontactwebsite design tutorials
 

 

 
 

To the index

JavaScript

  • How can I add 5 minutes to now?
  • How do I assign a JavaScript object to a CF variable?
  • Beginner

    How can I add 5 minutes to now?

    d=new Date();
    alert(d);
    d.setHours(d.getHours() + 5);
    alert(d);

    to question

    How do I assign a JavaScript object to a CF variable?

    JavaScript code is executed on the client, and CF code is executed on the server, so you can't just pass a JavaScript client variable to CF.

    There are only three ways to get JavaScript variables to CF

    1. Pass them through an HTML form.
    2. Pass them as URL parameters.
    3. Use JavaScript to write a cookie, and read the cookie in CF.

    Note that all three methods require two pages. The first page executes the JavaScript code, then sends the values back to the server within a second page request.

    So, in one page, you might have something like this

    <script LANGUAGE="JavaScript">
    location.href = 'secondpage.cfm?colordepth=' + screen.colorDepth;
    </script>

    In the second page, you can then reference that variable:

    The color depth is <cfoutput>#URL.colordepth#</cfoutput>.

    http://www.depressedpress.com/DepressedPress/Content/ColdFusion/Essays/GIFAsPipe/

    to question