Jump to content

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

php can't do a confirm box. it can do a confirm page, but i'm pretty sure the Javascript confirm box is what you want. If they click Cancel, it should just stay on the page. what does your code look like right now for the delete links?

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.