how to do "comfirm delete dialog box" before confrim delete

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kang jia
    New Member
    • Jun 2007
    • 88

    how to do "comfirm delete dialog box" before confrim delete

    hi

    currently, i would like to do a "confirm delete dialog box" , before user really decide to delete. so when user click delete, dialog box will pop up , saying "confirm delete ?" if yes, then go to delete page, otherwise still remain in the same page. i don;t know how to do it, is there any simple method to solve this?

    any one can help? thanks
  • mwasif
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    Use confirm() function in the following context
    [CODE=javascript]onSubmit="retur n confirm('Do you want to delete?');"[/CODE]

    Comment

    • kang jia
      New Member
      • Jun 2007
      • 88

      #3
      Originally posted by mwasif
      Use confirm() function in the following context
      [CODE=javascript]onSubmit="retur n confirm('Do you want to delete?');"[/CODE]
      i am quite new to this. if "Yes" it should like to delete page else it will remain in the same page. there must be a place to link ba? hmm... can help me with this, thanks :)

      PS, currently my application is like this: when user click "delete" link, it will just delete without any pop up box. it is very dangerous because user may accidently delete what they are not supposed to delete.

      Comment

      • mwasif
        Recognized Expert Contributor
        • Jul 2006
        • 802

        #4
        Make your link <a> look like this
        [HTML]<a href="http://some page link" onClick="return confirm('Do you want to delete?');">Del ete</a>[/HTML]

        If you click on OK, it will proceed to the delete page otherwise stays on the same page.

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          To do this without using javascript, you can use an intermediate page. Something like this:

          delete.php has the form to select the record to delete. Submitting the form goes to...
          confirm_delete. php will ask the User if he really wants to delete that record. Clicking delete will link to...
          dbi/delete.php will actually delete the record. Then it redirects back to delete.php.

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            Originally posted by pbmods
            To do this without using javascript, you can use an intermediate page. Something like this:

            delete.php has the form to select the record to delete. Submitting the form goes to...
            confirm_delete. php will ask the User if he really wants to delete that record. Clicking delete will link to...
            dbi/delete.php will actually delete the record. Then it redirects back to delete.php.
            I'd also reccomed somthing like this, its a little more 'user-friendly' than having a confirm box popping up, in my optinion.
            Not to mention that this removes the need for extra Javascript, which is always a good thing.

            Comment

            • kang jia
              New Member
              • Jun 2007
              • 88

              #7
              Originally posted by mwasif
              Make your link <a> look like this
              [HTML]<a href="http://some page link" onClick="return confirm('Do you want to delete?');">Del ete</a>[/HTML]

              If you click on OK, it will proceed to the delete page otherwise stays on the same page.
              it seems your suggestion does not work , my code is in the following:
              [code=PHP]
              $userid = $_SESSION['userid'];
              $sql1 = "SELECT * FROM orders WHERE id = '$userid'";

              $results1 = mysql_query($sq l1);
              if (mysql_num_rows ($results1) == 0) {
              echo "No items in your shopping cart yet<br>";
              echo "<a href = 'index.php'>Go back to main page</a>";
              } else {
              echo "<table border = 1><tr><th>Title </th><th>Brand</th><th>current price(1 piece)</th><th>quantity </th><th>size</th><th>delete?</th></tr>";
              while ($row1 = mysql_fetch_arr ay($results1)) {
              $poster_id = $row1['imageid'];
              $quantity=$row1['quantity'];
              $size=$row1['size'];
              $sql2 = "SELECT * FROM ladies WHERE id = '$poster_id'";
              $results2 = mysql_query($sq l2);
              $row2 = mysql_fetch_arr ay($results2);
              $title = $row2['title'];
              $brand = $row2['brand'];
              $price = $row2['price'];
              $cprice = $price * $cur->rateFromSGD($c urrency);
              $rprice=round($ cprice,2);
              $tprice+=$rpric e;
              //echo "<tr><td>".$tit le."</td><td>".$artis t."</td><td>".$cpric e."</td></tr>";
              echo "<tr><td>".$tit le."</td><td>".$brand ."</td><td>".$rpric e."</td><td>".$quant ity."</td><td>".$size. "</td><td><a href=\"do_delet e3.php?id=".$po ster_id."\" onClick='return confirm('Do you want to delete?');'>Del ete</a></td></tr>";

              }
              [/code]

              in fact, there should two options, if click "yes" then go to delete.php, else remain, but after i try out this code, it seems it does not pop up anyting, it seems like they ignore this piece of code, can help me sovle this ASAP, because my project time is near to due. thanks

              Comment

              • code green
                Recognized Expert Top Contributor
                • Mar 2007
                • 1726

                #8
                it seems your suggestion does not work
                That is because you have coded what you think it should be and not what Atli wrote
                Code:
                echo "<tr><td>".$title."</td><td>".$brand."</td><td>".$rprice."</td><td>".$quantity."</td><td>".$size."</td><td><a href=\"do_delete3.php?id=".$poster_id."\" onClick='return confirm('Do you want to delete?');'>Delete</a></td></tr>";
                OK, for a start do away with the awful escapes on the quotes.
                You have missed at least one. Write single quotes inside php and double quotes inside HTML. Then concatenate the two together [PHP]echo '<tr><td>'.$tit le.'</td><td>'.$brand .'</td><td>'.$rpric e.'</td><td>'.$quant ity.'</td><td>'.$size. '</td><td><a href="do_delete 3.php?id='.$pos ter_id.' " onClick="return confirm('Do you want to delete?')";>Del ete</a></td></tr>';[/PHP]Think i've done it right

                Comment

                Working...