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
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>

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

$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 &

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.