Jump to content

[SOLVED] PHP confirm message box


Alexhoward

Recommended Posts

Hi guys,

 

So, i'm pulling back images in a loop, and on each image i have a delete link that goes to something like:

 

images.php?delete=1&id=28

 

so it will delete the image with an id of 28 from MySQL

 

however i would like to have an "are you sure?" YesNo message box pop up.

 

Does anyone know if this is possible?

 

found a way through javascript but can't pass the variables as it calls a set function...

 

Thanks in advance!

 

Add Some Music

http://www.addsomemusic.co.uk

Link to comment
https://forums.phpfreaks.com/topic/141501-solved-php-confirm-message-box/
Share on other sites

Hi,

 

Problem is, as i loop through the results i echo the images, then the href can use those results to link with.

 

but with java script i have to use:

 

<a href="#" onclick=" ConfirmChoice(); return false;">

 

which calls:

 

<script language="javascript">

function ConfirmChoice() 

{ 

answer = confirm("Are you sure you want to delete this gallery?")

if (answer !=0) 

{ 

location = "where ever"

} 

}

</script>

This may be a better way. I use this a lot

 

<script>function delete() {

var answer = confirm("Do you want to delete this gallery?")

if (answer){

	window.location = "http://site.com/to/where/you/want/to/delete";

}

}</script>

 

And the button to make this pop up is...

<form><input type="button" onclick="delete()" value="Delete Gallery"></form>

 

<script>function delete(id) {

   var answer = confirm("Do you want to delete this gallery?")

   if (answer){

      window.location = "http://site.com/to/where/you/want/to/delete?delete=1&id=" + id;

   }

}</script>

<form><input type="button" onclick="delete(28)" value="Delete Gallery"></form>

 

But if you are using a form you could just use that to submit the form.

 

$delete_id = 28;
echo "<form><input type=\"button\" onclick=\"delete('$delete_id')\" value=\"Delete Gallery\"></form>";

 

Then


<script>function delete(DeleteId) {

   var answer = confirm("Do you want to delete this gallery?")

   if (answer){

      window.location = "http://site.com/?delete="+DeleteId;

   }

}</script>

That + might need to be changed to &

Where you have a link from the gallery to delete that gallery replace the link with that javascript button. Than you just change the javascript to this

 

<script>function delete() {

   var answer = confirm("Do you want to delete this gallery?")

   if (answer){

      window.location = "http://site.com/to/where/you/want/to/delete/images.php?delete=1&id='.$id.'";

   }

}</script>

 

and set $id the the image ID

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.