Professional Web Applications Themes

Problem saving data and closing popup windows - Coldfusion - Advanced Techniques

I seem to be missing something, but don't know what. :confused; I have a screen from which a user can click on a button that brings up a popup window. The user can then enter information for a new contact in that window. What is supposed to happen then is that the user clicks on save, the data is saved to the database and the information is returned to the calling screen and the popup window is closed. What is happening is the data is being saved (the page posts to itself and runs SQL to save toa database), but ...

  1. #1

    Default Problem saving data and closing popup windows

    I seem to be missing something, but don't know what. :confused;

    I have a screen from which a user can click on a button that brings up a popup
    window. The user can then enter information for a new contact in that window.
    What is supposed to happen then is that the user clicks on save, the data is
    saved to the database and the information is returned to the calling screen and
    the popup window is closed.

    What is happening is the data is being saved (the page posts to itself and
    runs SQL to save toa database), but I can't seem to close the form and return
    the data to the calling form. I thought I could use javascript to do it, but
    the javascript code doesn't seem to execute after the data is saved. If I
    reset the page, the javascript does run.

    I know how to have the javascript run and return information to a calling page
    if I don't have data to save first. Can anyone help me figure out what I am
    missing? Just a high level explanation of the process of getting the popup to
    close and return after saving data would probably suffice. Examples are always
    appreciated, of course. :)

    DeliK Guest

  2. #2

    Default Re: Problem saving data and closing popup windows

    Your approach may not work on all browsers -- since there is too much happening
    between the user's click and the attempt to close the window (browsers
    increasingly block that sort of thing).
    You may need to immediately close the popup and post, the form, to the calling
    window.

    That said, here's an outline of an approach that might work:

    Write a javascript variable, say "bFormSubmissionComplete =false" to the HTML
    header of the popup.

    The form processing code would set this flag to true (Assumes that you do all
    logic first and then write HTML last).

    At the end of the body tag, javascript would fire that closes the window if
    the flag is true.

    Alternatively, if you have good layered-architecture code:
    On a virgin popup, write just the needed form HTML.
    On a successful form submission, just write the window-closing javascript.

    Cheers,
    -- MikeR


    MikerRoo Guest

  3. #3

    Default Re: Problem saving data and closing popup windows

    Process

    Open opoup
    User input
    save data
    read saved data
    assign data that has been read to js vars
    assign js vars to "main" window
    close popup.

    The attached code should give you a starting point.

    Ken

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>
    <head>
    <title>Untitled</title>
    </head>

    <body>
    <cfif isdefined("form.submit")>
    <cftry>
    <cftransaction>
    <cfquery name="rs_save" datasource="dsn">
    Insert Into myTable(column1)
    Values('#form.text1#')
    </cfquery>
    <cfquery name="rs_id" datasource="dsn">
    Select Max(rec_Id) As MaxId
    From myTable
    </cfquery>
    <cfquery name="rs_read" datasource="dsn">
    Select column1
    From myTable
    Where rec_Id = #rs_id.MaxId#
    </cfquery>
    <script language="JavaScript">
    <cfoutput query="rs_read">
    var myText = "#rs_read.column1#";
    </cfoutput>
    opener.myText.value = myText;
    self.close;
    </script>
    </cftransaction>
    <cfcatch type="Any">
    Sorry error....
    </cfcatch>
    </cftry>
    </cfif>
    <cfoutput>
    <form action="#SCRIPT_NAME#" method="post" name="form1" id="form1">
    <input type="text" name="text1">
    <input type="submit" name="submit" value="Save Data">
    </form>
    </cfoutput>
    </body>
    </html>

    The ScareCrow Guest

Similar Threads

  1. Question After I closing of a popup window, how do I move it to the Top of the page
    By Chandan Dash in forum Macromedia Dynamic HTML
    Replies: 0
    Last Post: November 3rd, 07:22 AM
  2. closing popup window moves mouse to top of page
    By Jamie9470 in forum Macromedia Dynamic HTML
    Replies: 4
    Last Post: April 25th, 01:02 AM
  3. Closing Popup window
    By ReidarT in forum Dreamweaver AppDev
    Replies: 1
    Last Post: March 9th, 11:25 AM
  4. Movie Closing?? & Windows Closing??
    By JPrice in forum Macromedia Director Lingo
    Replies: 0
    Last Post: July 29th, 01:17 AM
  5. Saving serialized data to database problem
    By Tommy Christian in forum ASP.NET General
    Replies: 0
    Last Post: July 25th, 08:26 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