Confirm delete

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mariolopes
Forum Contributor
Posts: 102
Joined: Sun May 22, 2005 7:08 am

Confirm delete

Post by mariolopes »

Hi
I have one grid that i made myself. I need to confirm the delete option, maybe wuth Javascript. Any help, please?
Thank you
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Confirm delete

Post by Christopher »

Put the Yes/No for the delete in a hidden div that is shown when they click the Delete link.
(#10850)
User avatar
SimpleManWeb
Forum Commoner
Posts: 57
Joined: Wed Dec 30, 2009 4:15 pm
Location: New Hampshire, USA

Re: Confirm delete

Post by SimpleManWeb »

here is the simple javascript that you can either attach to the 'onsubmit' form, this is assuming you are using a button to process the delete action.

Code: Select all

 
   return confirm('Are you sure you want to delete this?');
 
I didn't test that code, but that should work.

Hope this helps.
mariolopes
Forum Contributor
Posts: 102
Joined: Sun May 22, 2005 7:08 am

Re: Confirm delete

Post by mariolopes »

Hum...
I don't have any form I only have a link to a php file who deletes the record. Please look at the following code;
echo "<td>"; echo "<a href='Apagar.php?Id=";echo $row[Id];echo "'>Delete</a>";echo "</td>";
I have to use one form?
Thank you
lshaw
Forum Commoner
Posts: 69
Joined: Mon Apr 20, 2009 3:40 pm
Location: United Kingdom

Re: Confirm delete

Post by lshaw »

Just use <a onclick=""> instead of onsubmit="". I have not tested it but i think it would work. The hidden div would work best for this in my opinion.
User avatar
SimpleManWeb
Forum Commoner
Posts: 57
Joined: Wed Dec 30, 2009 4:15 pm
Location: New Hampshire, USA

Re: Confirm delete

Post by SimpleManWeb »

lshaw is correct. The onclick will work just fine. Use something like this

Code: Select all

 
      echo "<td>"; 
      echo "<a href='Apagar.php?Id=";
      echo $row[Id];
      echo "' onclick='return confirm(\"Are You Sure you want to delete this?\");'>Delete</a>";
      echo "</td>";
 
What this does is cancels out the click if the person doesn't confirm the question. Again, this is untested but it should get you very close.
mariolopes
Forum Contributor
Posts: 102
Joined: Sun May 22, 2005 7:08 am

Re: Confirm delete

Post by mariolopes »

Works fine guys, solved my problem
Thank you
Post Reply