Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> A Simple Javascript Help Required
apple
post Dec 1 2006, 09:14 AM
Post #1


Newbie [Level 2]
**

Group: Members
Posts: 31
Joined: 9-August 06
Member No.: 28,049



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.'

CODE
$result = mysql_query("select * from comments order by id desc limit 10");
//the while loop
while($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());

}
Go to the top of the page
 
+Quote Post
shadowx
post Dec 1 2006, 01:18 PM
Post #2


A clever man learns from his own mistakes, a WISE man learns from those of OTHERS
***********

Group: [HOSTED]
Posts: 1,035
Joined: 12-April 06
From: Essex, UK
Member No.: 21,719



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 smile.gif Im ok with PHP, not so good with JS so if its PHP i can possibly give a hand.
Go to the top of the page
 
+Quote Post
hts
post Dec 1 2006, 05:55 PM
Post #3


Advanced Member
*******

Group: Members
Posts: 138
Joined: 30-September 06
From: Iasi, Romania
Member No.: 30,851



QUOTE

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 biggrin.gif..

This post has been edited by hts: Dec 1 2006, 06:02 PM
Go to the top of the page
 
+Quote Post
midnitesun
post Dec 3 2006, 08:32 AM
Post #4


Premium Member
********

Group: Members
Posts: 181
Joined: 22-February 06
Member No.: 19,007



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 :

CODE
<a href="java script:doConfirmation('<?=$content_id;?>','<?=$content_title?>')">delete</a>


and put this in head section of your script :

CODE

<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 :

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
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Javascript Slideshow Tutorial(4)
  2. Javascript Close Window(15)
  3. One Click Copy And Paste To Clipboard(5)
  4. Adding Rows & Columns In Html Table Using Javascript(1)
  5. I'm Making My Own Javascript Only Rpg :d(7)
  6. What's The Relationship Between Javascript And Java(5)
  7. Javascript : No Right Click Script !@(12)
  8. Hiding <div> Boxes With Javascript(8)
  9. My Little Javascript(0)
  10. Highlight A Word In Javascript. Help!(2)
  11. How Do You Make A Javascript Calculator?(11)
  12. Help With Javascript Calculator Returning "nan"(2)
  13. Great Javascript Script Source(2)
  14. Web Applications: J2ee Or Javascript/css/html(1)
  15. Opera Browser + Javascript + Embeded Sound(0)
  1. Javascript - What's Your Browser?(3)
  2. Javascript Events Not Working For Ie(6)
  3. I`m New To Javascript.(5)
  4. Special Wii Javascript(2)
  5. Javascript Error(2)
  6. Is It Possible To Create A Web Based Mmo In Javascript?(4)
  7. Capturing Username Of Computer(3)
  8. Javascript Object Node Referencing Help(5)
  9. Flash And Javascript Interaction(1)
  10. Document.write & Noscript Questions (javascript)(1)
  11. Java Vs Javascript(11)
  12. Adjusting Rows/cols Of Frames In Frameset Using Javascript Is Not Working In Firefox 3 Is Not Working(4)
  13. Need Help With Javascript Drag And Drop Script(2)


 



- Lo-Fi Version Time is now: 7th October 2008 - 12:12 AM