Professional Web Applications Themes

Passing Coldfusion Variable to Javascript - Coldfusion - Advanced Techniques

Does anyone know how to pass the contents of a coldfusion variable into Javascript?? If I have the entire javascript hard coded onto the cfm page, the coldfusion variable is easy to access using <cfoutput> tags. This is not a problem. However, I do not want to hard code the .js file into every cfm page on my web site. I want to have a single .js page that is referenced , ie <script language="JavaScript1.2" src="nav.js"></script> so if I make a change to the ..js file, I only have to do it once, not on every fcm page. Please let ...

  1. #1

    Default Passing Coldfusion Variable to Javascript

    Does anyone know how to pass the contents of a coldfusion variable into
    Javascript??

    If I have the entire javascript hard coded onto the cfm page, the coldfusion
    variable is easy to access using <cfoutput> tags. This is not a problem.

    However, I do not want to hard code the .js file into every cfm page on my web
    site. I want to have a single .js page that is referenced , ie <script
    language="JavaScript1.2" src="nav.js"></script> so if I make a change to the
    ..js file, I only have to do it once, not on every fcm page.

    Please let me know if anyone has a simple solution to this problem. Thanks

    beege2005 Guest

  2. #2

    Default Re: Passing Coldfusion Variable to Javascript

    Create the variable before you call the javascript and use the cfoutput tag. By the way, in version 7 there is a toscript function you may find handy.
    Dan Guest

  3. #3

    Default Re: Passing Coldfusion Variable to Javascript

    Have you thought about having CF generate your JavaScript page with the
    variables you wish to set for each CFM page.

    Start with your JavaScript (.js) file, change the extension to
    ColdFusion (.cfm), have the new CFM file write your JavaScript (similar
    to the way you do HTML) and then call the CFM page

    <script src="nav.cfm" type="text/javascript"></script>

    As long as nav.cfm return JavaSccript, then you are OK.

    Hint: You may wnat to test your CFM page first to ensure there are no
    errors, then add <cfsetting enablecfoutputonly="No"
    showdebugoutput="No"> to ensure that debug information is not
    displayed.

    I hope this answers your question.

    Zeke_the_Geek Guest

Similar Threads

  1. using javascript variable in coldfusion
    By vivekshankar in forum Coldfusion - Getting Started
    Replies: 4
    Last Post: October 27th, 06:07 AM
  2. Variable Passing, Javascript to Coldfusion
    By noobie2005 in forum Coldfusion - Getting Started
    Replies: 11
    Last Post: December 1st, 04:41 PM
  3. Passing CF variable value to JavaScript function
    By Scott in forum Coldfusion - Getting Started
    Replies: 2
    Last Post: November 11th, 08:40 PM
  4. passing variable to javascript pop-up window
    By jr_serrano in forum Macromedia Dynamic HTML
    Replies: 0
    Last Post: July 6th, 08:55 PM
  5. Replies: 7
    Last Post: July 17th, 04:54 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139