Page 1 of 1

Confirm delete

Posted: Sat Jan 23, 2010 5:45 pm
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

Re: Confirm delete

Posted: Sat Jan 23, 2010 8:50 pm
by Christopher
Put the Yes/No for the delete in a hidden div that is shown when they click the Delete link.

Re: Confirm delete

Posted: Sat Jan 23, 2010 8:55 pm
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.

Re: Confirm delete

Posted: Mon Jan 25, 2010 10:39 am
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

Re: Confirm delete

Posted: Mon Jan 25, 2010 2:46 pm
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.

Re: Confirm delete

Posted: Mon Jan 25, 2010 10:31 pm
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.

Re: Confirm delete

Posted: Tue Jan 26, 2010 4:44 am
by mariolopes
Works fine guys, solved my problem
Thank you