apple 0 Report post Posted December 1, 2006 Can somebody help me in creating a very simple javascript.. for example, the following code is example to delete a row from mysql.. all i want to do is.. that, when i click on delete, it gives a popup window , asking me if i really want to delete the row.. if i say Yes then it takes the action.. but if i say no then it takes back.' $result = mysql_query("select * from comments order by id desc limit 10");//the while loopwhile($r=mysql_fetch_array($result)){//getting each variable from the table$id = $r["id"];$self = $_SERVER['PHP_SELF'];echo $r["comment"];echo "<br />";echo "<a href = \"$self?id=$id\">delete</a>";}if(isset $_GET['id'])){$id = $_GET['id'];// --------- here code to connect to mysql and select database -----------$query= mysql_query("delete FROM comment where id =$id")or die(mysql_error());} Share this post Link to post Share on other sites
shadowx 0 Report post Posted December 1, 2006 hey what code help are you after? Do you mean you want a javascript page which will give you a link/button to delete a row and then this page goes to a PHP script which carries out the action? OR do you want a javascript script to do the actual deleting?I only ask because the code you posted is PHP and im confused!And what is the problem you're having? Is it that you simply need this script written or there is an error you are getting? If theres an error youre getting then post us the error and we can hopefully help Im ok with PHP, not so good with JS so if its PHP i can possibly give a hand. Share this post Link to post Share on other sites
hts 0 Report post Posted December 1, 2006 (edited) if(window.confirm("Are you sure?")) {//redirect to your delete file}else {//write an error message or whatever}This will pop a dialog box with options "OK" and "Cancel"...hope its ok for what you need..write it as a function, then call the function in a link..or whatever, I think you can handle..I`m not too good at JS either, I handle ok php, html, css, but NOT javascript .. Edited December 1, 2006 by hts (see edit history) Share this post Link to post Share on other sites
midnitesun 0 Report post Posted December 3, 2006 i guess i replied to a previous post of yours about deleting a particular row, since now you want a confirmation box i might as well suggest you to use another page to handle deleting, it will make life easy for you and you will understand it better i hope, so now we got to make some more modifications to the code , first put the following code in your original page where delete link is : <a href="java script:doConfirmation('<?=$content_id;?>','<?=$content_title?>')">delete</a> and put this in head section of your script :<script language="JavaScript">function doConfirmation(content_id,content_title) {if (confirm("Are you sure you want to delete " +content_title+ " ?")){window.location="delete.php?id="+content_id;}}</SCRIPT> now in make another page called delete.php and put the following code :?>ob_start();if(isset $_GET['id'])){$id = $_GET['id'];// --------- here code to connect to mysql and select database -----------$query= mysql_query("delete FROM comment where id =$id")or die(mysql_error());header("location:some.php?action=deleted");} ?> if you have any doubts please post back Share this post Link to post Share on other sites