SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict manipura's Avatar
    Join Date
    Apr 2001
    Location
    Calgary,AB
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Java Script confirm()

    I used confirm... It comes up saying ok and cancel. How do I get it to execute one script if you press ok and a different one when you press cancel.

  2. #2
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if (confirm(...)) { function1(); /*okay*/ } else { function2(); /*cancel*/}

  3. #3
    SitePoint Addict manipura's Avatar
    Join Date
    Apr 2001
    Location
    Calgary,AB
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, thanks, that helped... But now my question is can I put a PHP script in it? I tried it.. In the else{} I have an alert()

    if you press ok It will run a PHP script that will delete a row from a MySQL table.

    Now, when I run it. If I press cancel, it still deletes the row from the DB and run's the alert(). If I press cancel I ONLY want it to run the alert.

  4. #4
    SitePoint Evangelist ucahg's Avatar
    Join Date
    Apr 2001
    Location
    Sarnia, Ontario, Canada
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP is serverside. What you want is clientside. In order to do what you are talking about, you will need to refresh the page with that choice in the url, or something like that.
    Code:
    if (confirm(...)) {
      location.href="<?=$PHP_SELF ?>?deleterows=true";
    }
    else {
      alert("nothing deleted.");
    }
    and if you don't want the new page to load, through in a 204 No Content header, and it will stay on the current page. Hope this helps.

  5. #5
    SitePoint Addict manipura's Avatar
    Join Date
    Apr 2001
    Location
    Calgary,AB
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now I don't know why I didn't think of that.


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
  •