Page 1 of 1

delete link to delete items using javascript

Posted: Tue Jul 24, 2007 10:19 am
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.

Posted: Tue Jul 24, 2007 10:26 am
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.

Posted: Tue Jul 24, 2007 10:42 am
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? :(

Posted: Tue Jul 24, 2007 1:16 pm
by miro_igov
what is the delete function ?