Solved

using java script "confirm" with PHP

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

730 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