Jump to content
xisto Community
Sign in to follow this  
apple

A Simple Javascript Help Required

Recommended Posts

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

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

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 by hts (see edit history)

Share this post


Link to post
Share on other sites

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.