SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Member
    Join Date
    Oct 2002
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    confirm help...an easy one for the PROS!

    Here is my javascript:

    <script language="javascript">
    function confirmDelete() {
    if (confirm("Are you sure you want to delete this gallery? This cannot be undone!"))
    document.window.open();
    else
    document.write("<font color=RED><i>**Operation Cancelled</i></font><br><a href=photogalleryadmin.php>Return the Admin Page</a>");
    }
    </script>

    Now this works just fine. However, what I really want to do is call an actual PHP page on the else rather than doing document.write

    Can anyone help?
    THanks!
    - Patrick

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    else
    window.location.href='yourpage.php';
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    Rehab is for quiters! spartan's Avatar
    Join Date
    Apr 2002
    Location
    Cape Town, South Africa
    Posts
    343
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you just want to redirect to another page,
    you could just do this...
    Code:
    document.location.href = "mypage.htm"
    Spartan
    ---------------------
    It's like our sergeant told us before one trip into the jungle. Men! Fifty of you are leaving on a mission. Twenty-five of you ain't coming back.
    -Mr.Payne

  4. #4
    Rehab is for quiters! spartan's Avatar
    Join Date
    Apr 2002
    Location
    Cape Town, South Africa
    Posts
    343
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    damn
    I you beat me to it
    /me feels inadequate not to mention SLOW!
    Spartan
    ---------------------
    It's like our sergeant told us before one trip into the jungle. Men! Fifty of you are leaving on a mission. Twenty-five of you ain't coming back.
    -Mr.Payne

  5. #5
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by spartan
    damn
    I you beat me to it
    /me feels inadequate not to mention SLOW!
    Hehe, not only did I beat ya to it, but you made an error! (don't look now...save that for when you are emotionally stabilized from the shock of posting 2nd )

    location is NOT a sub-object to document, but rather to window. Since window by default is implied, the only objects or references that can be validly(<-- that a word?) placed in front location are: (in no particular order)
    • nothing (a reference to the containing window is implied)
    • window
    • top
    • self
    • parent
    • Any valid reference to any current window object (popups or frames)
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  6. #6
    SitePoint Member
    Join Date
    Oct 2002
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the responses guys but unfortunately I tried both of your snippets of code and neither worked.
    It just refreshes the page I am on. The onlye thing that seems to work right now is the document.write command.

    Any ideas?

    Thanks for the help
    - Patrick

  7. #7
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How is the confirmDelete() function triggered?
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  8. #8
    SitePoint Member
    Join Date
    Oct 2002
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <a href='javascript:confirmDelete()'>Remove</a>

  9. #9
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, the more I look at your function, the more confusing it seems.
    1. document.window.open(); isn't valid, not sure what you are doing here....
    2. Why write a cancellation to the page with document.write? Why not just another alert?
    I'm going to layout an example here that uses a pretty different concept for achieving what you are going after...
    Code:
    <script language="javascript">
    function confirmDelete() {
    	if (confirm("Are you sure you want to delete this gallery? This cannot be undone!"))
    		return true;
    	else {
    		alert('Deletion operation cancelled');
    		return false;
    		}
    	}
    </script>
    
    <a href="delete.php" onClick="return confirmDelete();">Remove</a>
    This (IMO) is a much more elegant process, plus it will work for people who have javascript turned off, they just won't have the benefit of the confirmation.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  10. #10
    SitePoint Member
    Join Date
    Oct 2002
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    YES YES YES! Almost there. I'm a newbie to Javascript so I wasn't sure how else to do it. This is starting to look sweet. However, when I click OK on the alert my PHP function still gets called so the gallery deletes anyway.

    My page is being created with PHP so this is what the actual button looks like:

    echo "<td><a href=photogalleryadmin.php?id=".$row->gallery_id."&remove=yes onClick=confirmDelete()>Remove</a></td>";

    I didn't include the whole thing before cause I though it would be too much info.

    Thanks for the help!

    - Patrick

  11. #11
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You missed the most important part! The onClick event needs to 'listen' for a return from the function so it knows whether or not to cancel the default action (which is obeying the href...)

    onClick=return confirmDelete()

    However, I also think your HTML output via PHP needs to be modified. HTML likes having double quotes around it's attribute values... Try changing it up like this...
    PHP Code:
    echo "<td><a href=\"photogalleryadmin.php?id=".$row->gallery_id."&remove=yes\" onClick=\"return confirmDelete();\">Remove</a></td>"
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  12. #12
    SitePoint Member
    Join Date
    Oct 2002
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    WOO HOO!!!!
    Works like a friggin CHARM!
    Thanks so much.
    Are you a Javascript guru?
    I have lots of projects that I'll need someone like you on...for pay too!
    Email me if you are interested.

    Thanks again!
    - Patrick

  13. #13
    Rehab is for quiters! spartan's Avatar
    Join Date
    Apr 2002
    Location
    Cape Town, South Africa
    Posts
    343
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by beetle
    Hehe, not only did I beat ya to it, but you made an error! (don't look now...save that for when you are emotionally stabilized from the shock of posting 2nd )
    nothing that a couple of years of therapy wont cure!


    location is NOT a sub-object to document, but rather to window. Since window by default is implied, the only objects or references that can be validly(<-- that a word?) placed in front location are: (in no particular order)
    • nothing (a reference to the containing window is implied)
    • window
    • top
    • self
    • parent
    • Any valid reference to any current window object (popups or frames)
    hmmm... but it works though
    why is it wrong then?
    Spartan
    ---------------------
    It's like our sergeant told us before one trip into the jungle. Men! Fifty of you are leaving on a mission. Twenty-five of you ain't coming back.
    -Mr.Payne

  14. #14
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Probably cuz you're testing it in IE, which as we all know is pretty-flexible on the code it accepts.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  15. #15
    Rehab is for quiters! spartan's Avatar
    Join Date
    Apr 2002
    Location
    Cape Town, South Africa
    Posts
    343
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    aha

    thanx for the info.

    BTW
    DIG THE SIG!

    LONG LIVE ASH!!!
    Spartan
    ---------------------
    It's like our sergeant told us before one trip into the jungle. Men! Fifty of you are leaving on a mission. Twenty-five of you ain't coming back.
    -Mr.Payne


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
  •