Professional Web Applications Themes

pass javascript variable to cold fusion - Macromedia ColdFusion

anyone know if there's a way to pass a Javascript variable to Cold fusion? Or a good article that shows how to do this?...

Sponsored Links
  1. #1

    Default pass javascript variable to cold fusion

    anyone know if there's a way to pass a Javascript variable to Cold fusion? Or a good article that shows how to do this?

    Sponsored Links
    timrande Guest

  2. #2

    Default Re: pass javascript variable to cold fusion

    I found this somewhere a while back and use it at times...

    find_res.cfm
    --------------------------------------------------
    <CFIF IsDefined("URL.ReturnTo")>
    <CFSET session.FormAction=URL.ReturnTo & ".cfm">
    <CFELSE>
    <CFSET session.FormAction="index.cfm">
    </CFIF>
    <html>
    <head>
    <title>Processing request</title>

    <!--- This function grabs the screen resolution and assigns the height and
    width
    values to hidden form variables.
    --->
    <SCRIPT LANGUAGE="JavaScript">

    function getscreen() {
    var screenW = 640, screenH = 480;
    if (pInt(navigator.appVersion)>3) {
    screenW = screen.width;
    screenH = screen.height;
    }
    else if (navigator.appName == "Netscape" && pInt(navigator.appVersion)==3
    && navigator.javaEnabled()) {
    var jToolkit = java.awt.Toolkit.getDefaultToolkit();
    var jScreenSize = jToolkit.getScreenSize();
    var url1;
    screenW = jScreenSize.width;
    screenH = jScreenSize.height;
    }

    <!--- Assign JavaScript Variables to Hidden Form Fields --->
    doent.f1.sw.value = screenW;
    doent.f1.sh.value = screenH;
    doent.f1.submit();
    }

    </SCRIPT>
    </head>

    <!---
    This code forces the form to run the getscreen function
    as soon as the page loads. Since the getscreen function has a
    submit function in it this page is never seen and the form fields are
    passed on to whatever page is set for the Form Action attribute.
    --->
    <body background="images/bground.jpg" onload="getscreen()">
    <CFOUTPUT>
    <form name="f1" action="#session.FormAction#" method="post">
    <input type="Hidden" name="sw">
    <input type="Hidden" name="sh">
    </form>
    </CFOUTPUT>
    </body>
    </html>

    -----end find_res.cfm--------------

    yourPage.cfm
    -----------------------------------------
    <CFIF Not IsDefined("session.screen_w")>
    <CFIF IsDefined("form.sw")>
    <CFSET session.screen_w=(form.sw * 0.9)><!--- same as 90% --->
    <CFELSE>
    <CFLOCATION addToken="no" URL="find_res.cfm?ReturnTo=index">
    </CFIF>
    </CFIF>
    ...

    Basically yourPage.cfm calls the find_res page if the needed form field is not
    available. find_res.cfm uses JS to populate 2 hidden form fields and submits
    it back to yourPage.cfm to use. It can be a little slow and may confuse users
    if they see the screen load(s), but it is a solution.

    CR


    CRidgway Guest

Similar Threads

  1. Discussion assign javascript variable into cold fusion
    By dev29 in forum ColdFusion
    Replies: 0
    Last Post: June 13th, 03:40 PM
  2. Migrating from Cold fusion 5 to Cold fusion 7
    By Ashish Khanna in forum Coldfusion Server Administration
    Replies: 1
    Last Post: October 6th, 12:37 PM
  3. pass a variable from javascript to actionscript2.0 inopera9 browser
    By kingdom_of_revenge in forum Macromedia Flash Data Integration
    Replies: 0
    Last Post: February 1st, 08:14 AM
  4. Accessing Cold Fusion application variable usingJavascript
    By mdemahy in forum Coldfusion - Advanced Techniques
    Replies: 2
    Last Post: May 6th, 03:35 PM
  5. Javascript variables to cold fusion
    By hivaluescomputing in forum Coldfusion - Advanced Techniques
    Replies: 1
    Last Post: February 25th, 03:52 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