delete link to delete items using javascript

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

delete link to delete items using javascript

Post by pleigh »

hi, i have a code here for deleting a record

Code: Select all

<a href="edit.php?eid=<?php echo $akey; ?>" name="edit">edit</a> | 
<a href="" name="delete" onclick="return setDeletemode(<?php echo $akey; ?>, true)">delete</a>


if (isset($_POST['delete'])) {
$del = delete_language_caption($eid);
				  			
if ($del) {
echo "<b>Successfully deleted this record.</b><br>";
echo "<meta http-equiv=\"refresh\" content=\"2;url=index.php\">";
} else {
echo "system error.";
}
}
and i have a javascript code so the end user wil be prompted confirming the deletion of this record

Code: Select all

function setDeletemode(lkey)
{
	mode = 'del';
	//lang_key = lkey;
	
	var answer = confirm("Are you sure you want to delete this item?");
	if (answer){
		return true;
	} else {
		return false;
	}
}
the problem is that when i tried to delete a record, it returns nothing.please help.
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

It does nothing because the href attribute of the anchor where you call setDeletemode is empty. If you enter some URL it will open it on true or will not open it on false result from setDeletemode, which means if you click OK it will open the URL and if you click cancel it will not.
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post by pleigh »

thank you for the reply.i have a function to delete a record, but unofrtunately, it was not handled when the delete link is clicked.how can i implement that? :(
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

what is the delete function ?
Post Reply