Solved

using java script "confirm" with PHP

Posted on 2003-10-27
3
261 Views
Last Modified: 2008-03-10
Hi,

I'm having some problem using Java Script and PHP together. I would like to have a link where I can delete a listed object from a DB. But the User should be asked if he really like to delete the record with a Java Script "confirm" Popup and if he choose no (Abort) the record will not be deleted.
My problem now is the record is deleted anyway doesn't matter if the user click "ok" or "Abort".
Please see my code below:
----------snip------------------------------------------------------------------------------
<?php

//some PHP code here......

?>

<script language="JavaScript">
<!--
if (confirm("Do you really like to delete the System ?")) {
      <?
      //delete the IP's from the Unit
      $query = "delete from unitip where UNIT = '$id'";
      mysql_query($query);
      ?>
      break;
}
else{
      break;
}

// -->
</script>

<?

//some more PHP code......

?>
----------snip------------------------------------------------------------------------------

do you have any idea how to make this work?

thanks & regards
Marc
0
Comment
Question by:bleuler
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 125 total points
ID: 9628501
you are mixing server side and client side.
Not possible.

WHat you want is this:
<a href="#" onClick="if (confirm("Do you really like to delete the System ?")) location='myphp?delete=yes';
return false">CLick to delete</a>

or similar
0
 
LVL 6

Expert Comment

by:mattjp88
ID: 9629533
what is happening is the php is getting exicuted before the confirm is even produced.  So what you need to do is have a link that will only go to the page that deletes the record when you click "OK", like what mplungjan said, or you could have one php page that will confirm and then if you click on it will foward you to delete page, if not it will bring you back a page.

-Matt
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 9629944
Any particular reason for the "B" grade?
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question