i want to display a confirmation message when a user clicks delete.can any1 tell me how i could do it with javascript and php
here's my code

$id=$r["sr_no"];
		if($r['district']==1 || $r['district']=='North')
		{
		$r['district']=North;
		echo "<tr><td >{$r['sr_no']}</td><td >{$r['name']}</td><td >{$r['designation']}</td><td >{$r['dte']}</td><td >{$r['ph_o']}</td><td >{$r['ph_m']}</td><td >{$r['ph_r']}</td><td >{$r['district']}</td><td >{$r['taluka']}</td><td >{$r['pan_name']}</td><td><a href='edit.php?cmd=edit&id=$id'>Edit</a></td><td><a href='edit.php?cmd=delete&id=$id' >Delete</a></td></tr>";
		echo "";}
if($_GET["cmd"]=="delete" || $_POST["cmd"]=="delete")
{
$id = $_GET["id"];

$sql=caseQuery("delete from designation where sr_no=$id");
if($result)
	  {
      redirect('edit.php');
	  }
	  else
	  {
	  echo "<p>cannot delete your data<p>";
	  }
}

Recommended Answers

All 9 Replies

try like this

<script>
function del_Users(id,name){
	if(confirm("Are you sure want to delete this ?")){
		document.location.href = 'xxx.php?act=del&id='+id+'&name='+name;
	}
}
</script>
<body>
<a href="javascript:del_Users(id,name)" class="tahoma11boldlink">delete</a>
</body>
</html>

then you retrive values from url get that values and write delete query.

hy,thanx alot.but i've to call the javascript function in php.how can i do it?

hy,thanx alot.but i've to call the javascript function in php.how can i do it?

see this example

<?php
if ($ID = '') {
echo "<script language=javascript>alert('Please enter a valid username.')</script>";
}
?>

we can write like this javascript in php

no no,i dnt mean that.what i meant was the 'href="javascript:del_Users(id,name)" ' has to be within php.as you can see in my 1st post,im displaying a table in php.so the javascript function call will be in php.how can i write that

no no,i dnt mean that.what i meant was the 'href="javascript:del_Users(id,name)" ' has to be within php.as you can see in my 1st post,im displaying a table in php.so the javascript function call will be in php.how can i write that

then write there only like my first post. you write html code in php. that html table put in form and cal javascript then redirect to edit.php what ever it is...

u mean like this?

<head>
<script>function del_Users(id,name)
{
if(confirm("Are you sure want to delete this ?"))
{document.location.href = 'xxx.phpact=del&id='+id+'&name='+name;	}
}</script>
</head>
<body>

echo "<tr><td><a href="javascript:del_Users(id,name)"> Delete</a></td></tr>";

this doesnot work

try this.

<?
echo "
<form name=formx method=post>
<table>
<tr>
<td>
<a href=javascript:del_Users(1)> Delete</a>
</td>
</tr>
<table>";
?>
<head>
<script>
function del_Users(id)
{
if(confirm("Are you sure want to delete this ?"))
{document.location.href = 'xxx.php?act=del&id='+id;	}
}</script>
</head>

thanx...i managed.did it like this

<a href='edit.php?cmd=delete&id=$id' onClick=\"return confirm('Are you  certain that you want to DELETE this record?')\" >Delete</a></td>

thanx...i managed.did it like this

<a href='edit.php?cmd=delete&id=$id' onClick=\"return confirm('Are you  certain that you want to DELETE this record?')\" >Delete</a></td>

mark as solve

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.