Jump to content

Archived

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

Alexhoward

[SOLVED] PHP confirm message box

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

Share this post


Link to post
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?

Share this post


Link to post
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>

Share this post


Link to post
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>

 

Share this post


Link to post
Share on other sites

Thanks for the reply

 

problem is i put the delete script on the same page, so...

 

images.php?delete=1&id=28

 

will delete image 28

 

therefore the java location needs to have these variables...?

Share this post


Link to post
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.

 

Share this post


Link to post
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 &

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Nice one!

 

got it working, but can only get to work with numbers, not variables that are text

Share this post


Link to post
Share on other sites

×

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.