Solved

using java script "confirm" with PHP

Posted on 2003-10-27
3
271 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

734 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