Professional Web Applications Themes

javascript page redirect with coldfusion query - Coldfusion - Advanced Techniques

Hello, I am trying to use javascript to redirect a page based on a checkbox. When the user clicks the checkbox it redirects the user to the same page but with different URL variables. The variable in the URL then activates the code shown below with the updates. Everything redirects fine and updates fine, however the user does not know that it was updated because the checkbox never goes checked unless the user specifically clicks refresh in their browser. I want the redirect to be able to have the box checked so the user knows the data has been changed ...

  1. #1

    Default javascript page redirect with coldfusion query

    Hello, I am trying to use javascript to redirect a page based on a checkbox.
    When the user clicks the checkbox it redirects the user to the same page but
    with different URL variables. The variable in the URL then activates the code
    shown below with the updates. Everything redirects fine and updates fine,
    however the user does not know that it was updated because the checkbox never
    goes checked unless the user specifically clicks refresh in their browser. I
    want the redirect to be able to have the box checked so the user knows the data
    has been changed successfully.

    Any ideas why the checkbox is not saying its checked?



    <cfif isdefined("URL.Action") and #URL.Action# eq "notificationon">
    <cfquery username="**********" password="**********" datasource="********">
    UPDATE Users
    SET Notification='on'
    where id=#GetUserdetails.id#
    </cfquery>
    </cfif>

    <cfif isdefined("URL.Action") and #URL.Action# eq "notificationoff">
    <cfquery username="*********" password="***********"
    datasource="************">
    UPDATE Users
    SET Notification='off'
    where id=#GetUserdetails.id#
    </cfquery>
    </cfif>


    <input type="checkbox"<cfif #GetUserdetails.Notification# is
    "on">checked</cfif> onclick="javscript: doent.location =
    'controlpanel.cfm?Action=notification<cfif #GetUserdetails.Notification# is
    "on">off<cfelse>on</cfif>'"> You have chosen <span style="color: red;"><cfif
    #GetUserdetails.Notification# is "off">not </cfif>to receive email
    notifications</span>





    davellaman Guest

  2. #2

    Default Re: javascript page redirect with coldfusion query

    Well, to point out the obvious, you need to put the GetUserDetails query AFTER the update queries in order to see the changes take effect. Otherwise, it would require an additional page reload.
    BSterner Guest

  3. #3

    Default Re: javascript page redirect with coldfusion query

    You appear to be basing that logic on the value of a field named Notification
    in a query named GetUserDetails, but I don't see such a query anywhere. It
    must be somewhere, or else nothing else will work. In fact the update won't
    work.

    So I'm guessing that you are doing this:
    1. Run a select query and getting at least two values (id and notification)
    2. Updating the notification
    3. Applying logic based on the value of notification before it was updated.

    By the way, does your form submit if you check or uncheck the box with a
    keyboard? I suspect not.



    Originally posted by: davellaman
    Hello, I am trying to use javascript to redirect a page based on a checkbox.
    When the user clicks the checkbox it redirects the user to the same page but
    with different URL variables. The variable in the URL then activates the code
    shown below with the updates. Everything redirects fine and updates fine,
    however the user does not know that it was updated because the checkbox never
    goes checked unless the user specifically clicks refresh in their browser. I
    want the redirect to be able to have the box checked so the user knows the data
    has been changed successfully.

    Any ideas why the checkbox is not saying its checked?



    <cfif isdefined("URL.Action") and #URL.Action# eq "notificationon">
    <cfquery username="**********" password="**********" datasource="********">
    UPDATE Users
    SET Notification='on'
    where id=#GetUserdetails.id#
    </cfquery>
    </cfif>

    <cfif isdefined("URL.Action") and #URL.Action# eq "notificationoff">
    <cfquery username="*********" password="***********"
    datasource="************">
    UPDATE Users
    SET Notification='off'
    where id=#GetUserdetails.id#
    </cfquery>
    </cfif>


    <input type="checkbox"<cfif #GetUserdetails.Notification# is
    "on">checked</cfif> onclick="javscript: doent.location =
    'controlpanel.cfm?Action=notification<cfif #GetUserdetails.Notification# is
    "on">off<cfelse>on</cfif>'"> You have chosen <span style="color: red;"><cfif
    #GetUserdetails.Notification# is "off">not </cfif>to receive email
    notifications</span>







    Dan Guest

  4. #4

    Default Re: javascript page redirect with coldfusion query

    Originally posted by: BSterner
    Well, to point out the obvious, you need to put the GetUserDetails query AFTER
    the update queries in order to see the changes take effect. Otherwise, it
    would require an additional page reload.

    if the updates require GetUserDetails, how can I possibly put it after?


    Originally posted by: Dan Bracuk
    By the way, does your form submit if you check or uncheck the box with a
    keyboard? I suspect not.

    Yea the form seems to submit fine using a keyboard.




    Sorry I forgot to display that query,



    <cfquery name="GetUserdetails" datasource="****" username="****"
    password="*****">
    SELECT *
    FROM Users
    WHERE UserName = '#Session.MM_Username#'
    </cfquery>


    so the users checks the check box, the user is then taken to the same URL but
    with different URL variables, the UPDATE scripts start working when the URL
    variables equal notificationoff or notificationon, everything is updated fine
    however when the page reloads the box still remains unchecked until you
    manually hit "Refresh" I want it to be checked upon the page being loaded.

    any ideas?


    davellaman Guest

  5. #5

    Default Re: javascript page redirect with coldfusion query

    davellaman,

    I'm going to help you solve this problem yourself.

    You have to trace through, looking at the value of the variable that you're
    using to define whether the checkbox is checked or not.

    Say I go to that page, and my notificationon is "on". I check the checkbox.
    What happens?

    First, the GetUserDetails query is run, which gets my current notificationon
    value (which is "on").

    Then, you do your whole cfif isDefined stuff and update the Users table with
    my new notification. But guess what? that doesn't go and change what's in my
    GetUserDetails query (so GetUserDetails.notificationon value is still "on").

    So, how would you solve this? Since you're changing something in the Users
    table, simply re-run the GetUserDetails query right after you do your UPDATE
    USERS query.

    All you have to do is trace through your code and think about what is getting
    set, when. Obviously you're using a value that is possibly incorrect, as you're
    doing an UPDATE on that table between when you're getting the information out
    to when you're actually using it in your code.

    Kronin555 Guest

  6. #6

    Default Re: javascript page redirect with coldfusion query

    Use the end of the url variable. That will be either on or off won't it?

    Originally posted by: davellaman
    if the updates require GetUserDetails, how can I possibly put it after?

    any ideas?



    Dan Guest

  7. #7

    Default Re: javascript page redirect with coldfusion query

    Originally posted by: Dan Bracuk
    Use the end of the url variable. That will be either on or off won't it?

    on second thought
    Why is it you said you needed the query again? What do get from it that you
    don't already have? Can't be the userid, because that's a session variable and
    the on/off decision can be based on a url variable.


    Originally posted by: davellaman
    if the updates require GetUserDetails, how can I possibly put it after?

    any ideas?






    Dan Guest

  8. #8

    Default Re: javascript page redirect with coldfusion query

    Yea, I could use the URL variable to tell whether the checkbox should be
    checked or not but that would only work when the userhas just changed it. What
    if they logged out and came back, then the code would be looking for a URL
    variable and it wont be there, so the checkbox wont be checked.

    I am trying to figure out if this is a javascript issue or coldfusion. Also,
    do I need to install some sort of page refresh to get this script to work?
    Like I said, the javascript does what its supposed to, it loads the new page
    with the correct URL and the coldfusion works perfectly fine as far as the
    update goes. But for some reason the checkbox isnt checked. Does this have
    something to do with the browser cache?

    the database holds either the value "on" or "off" so if the query result is
    on, the checkbox should be checked, and vice versa. Perhaps somehow when the
    page is redirected it is still running from the previous query where the value
    was off?

    thanks so far for the help just a little confused about why this wont work



    davellaman Guest

  9. #9

    Default Re: javascript page redirect with coldfusion query

    you were right, i put the query again after the update and it works excellent
    now. Thank you guys for all of your help! I guess it was running off of old
    values and the re-runing of the query grabed the new ones.


    Thanks again!

    davellaman Guest

Similar Threads

  1. How can query the Kontakt folder im mail server througha coldfusion page
    By Yasmin_lady in forum Coldfusion - Advanced Techniques
    Replies: 0
    Last Post: June 24th, 09:23 AM
  2. query the mail server through a coldfusion page
    By Yasmin_lady in forum Coldfusion - Advanced Techniques
    Replies: 1
    Last Post: June 24th, 07:54 AM
  3. Datagrid redirect query
    By shadrik in forum ASP.NET Data Grid Control
    Replies: 1
    Last Post: March 28th, 01:04 AM
  4. #24463 [Opn]: SQL Server Query + Redirect = 502 Error
    By nospam at kolbly dot com in forum PHP Development
    Replies: 0
    Last Post: August 5th, 06:50 PM
  5. Replies: 0
    Last Post: July 19th, 06: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