Solved

using java script "confirm" with PHP

Posted on 2003-10-27
3
258 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now