...

View Full Version : Javascript : Confirm Delete



mln_ndh
02-01-2012, 02:52 AM
Hi I really really really need your help since I have no idea about this.

How can I insert the Javascript Confirmation Alert into the del.php file?



I have this del.php file


<?php
require ("include/config.php");
$id=$_REQUEST['id'];

$strSQL = "DELETE FROM change WHERE id = '".$id."' ";
$objQuery = odbc_exec($conn,$strSQL);
if($objQuery)
{

echo "<script language='Javascript'>alert('Deleted.');
window.location=\""."index.php?action=syif\"</script>";

}
else
{
echo "Error Delete [".$strSQL."]";
}
odbc_close($conn);


?>



This is the confirmation javascript


<html>
<head>
<script type="text/javascript">
function show_confirm()
{
var r=confirm("Delete?");
if (r==true)
{
alert("Deleted!");
}
else
{
alert("Cancelled!");
}
}
</script>
</head>
<body>

<input type="button" onclick="show_confirm()" value="Show confirm box" />

</body>
</html>

devnull69
02-01-2012, 07:01 AM
This is a fuzzy question ... what does del.php have to do with the confirmation javascript? Please describe your problem, ideally step by step.

mln_ndh
02-01-2012, 08:52 AM
This is a fuzzy question ... what does del.php have to do with the confirmation javascript? Please describe your problem, ideally step by step.

Okay i have this del.php file. Then i wanted to add confirmation alert when deleting the data.

So, how can i add the confirmation alert into the del.php file?

I hope you understand my problem :)

devnull69
02-01-2012, 09:58 AM
What do you do with del.php? Where and how do you call it (page refresh, Ajax)? What do you do with the output of the script? Your information is not sufficient to answer those questions.

mln_ndh
02-01-2012, 10:15 AM
What do you do with del.php? Where and how do you call it (page refresh, Ajax)? What do you do with the output of the script? Your information is not sufficient to answer those questions.

Oh yeah i forgot. I have this changeshift.php file. The del.php file will be called here. I've bold the coding where it is called





$syif = $_REQUEST['idstaff_info'];
$sql ="SELECT DISTINCT staff_info.*, staff_shift.ss_name
FROM staff_info
INNER JOIN staff_shift
ON staff_shift.idstaff_shift = staff_info.idstaff_shift
WHERE staff_info.idstaff_info = '".$syif."' ";



$objExec = odbc_exec($conn, $sql);
$objResult = odbc_fetch_array($objExec);
if(!$objResult)
{
echo "Not found idstaff_info=".$_REQUEST["idstaff_info"];
}
else {

?>
<script type="text/ecmascript">"var time_variable; function getXMLObject()"</script>
<script type="text/javascript" src="calendar/calendar.js"></script>
<link rel="stylesheet" type="text/css" href="calendar/calendar.css" title="default" />
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form name="lina" method="post" action="tukarscript.php">
<table width="100%" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center">Penukaran Syif</td>
</tr>
<tr>
<td width="649"><p>&nbsp;</p>
<table width="593" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><div align="right">Nama :</div></td>
<td>&nbsp;</td>
<td><?php echo $objResult['si_name'];?></td>
</tr>
<tr>
<td><div align="right">Id Pekerja:</div></td>
<td>&nbsp;</td>
<td><?php echo $objResult['si_emp_num'];?></td>
</tr>
<tr>
<td width="213"><div align="right">Syif Sekarang:</div></td>
<td width="10">&nbsp;</td>
<td width="370"><?php echo $objResult['ss_name']; ?>
<input type="hidden" name="syif_lama" value="<?php echo $objResult['idstaff_shift'];?>" />
<input type="hidden" name="idstaff" value="<?php echo $objResult["idstaff_info"]?>" /></td>
</tr>
<tr>
<td><div align="right">Tukar Kepada Syif:</div></td>
<td>&nbsp;</td>
<td>
<label>
<select name="idstaff_shift" size="1" id="idstaff_shift">
<option selected="selected" value="<?php echo $idstaff_shift; ?><?php echo $idstaff_shift; ?>"></option>
<?php

$sql1 = "SELECT DISTINCT idstaff_shift, ss_name FROM staff_shift ";
$query=odbc_exec($conn,$sql1);
while (odbc_fetch_row($query)) {
$idstaff_shift = odbc_result($query,"idstaff_shift");
$ss_name = odbc_result($query,"ss_name");
printf ("<OPTION value=\"$idstaff_shift\">$ss_name</OPTION>");
}
odbc_free_result($query);
?>
</select></label></td>

</tr>
<tr>
<td width="213"><div align="right">Pilih Tarikh:</div></td>
<td width="10">&nbsp;</td>
<td><input type="text" name="dt_frm" value="<?php echo $dt_frm;?>" size="10" />
<a href="#" onClick="displayDatePicker('dt_frm', false, 'dmy', '/');"><img src="calendar/calendar.jpg" border="0"/></a> &nbsp; Hingga &nbsp;
<input type="text" name="dt_to" value="<?php echo $dt_to; ?>" size="10" />
<a href="#" onClick="displayDatePicker('dt_to', false, 'dmy', '/');"><img src="calendar/calendar.jpg" border="0"/></a></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
<td><input type="submit" name="submit" value="TERUSKAN" /></td>
</tr>
</table>
<p>&nbsp;</p></td>
</tr>
</table>
<p>
<?php
odbc_close($conn);
}
$SQLList = " select distinct syifTukar.*, staff_shift.ss_name
from syifTukar
inner join staff_shift
on syifTukar.idsyif_baru=staff_shift.idstaff_shift
where syifTukar.idstaff_info='".$objResult['idstaff_info']."' order by syifTukar.tarikh_mula asc ";
$RSTList = odbc_exec( $conn, $SQLList );
#$totalRows = odbc_num_rows( $RSTList );


?>
<p>&nbsp;</p>
<table width="522" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#EEEEEE">
<tr>
<td colspan="5"><div align="center">SEJARAH SYIF</div></td>
</tr>
<tr>
<td width="31" rowspan="2"><div align="center">NO</div></td>
<td colspan="2" align="center">TEMPOH SYIF</td>
<td width="86" rowspan="2"><div align="center">SYIF</div></td>
<td width="83" rowspan="2"><div align="center">TINDAKAN</div></td>
</tr>
<tr>
<td width="150"><div align="center">TARIKH MULA</div></td>
<td width="160"><div align="center">TARIKH AKHIR</div></td>
</tr>
<?php
$int = 1;
while ( odbc_fetch_row( $RSTList ) )
{

$tarikh_mula = odbc_result( $RSTList, "tarikh_mula" );
$tarikh_akhir = odbc_result( $RSTList, "tarikh_akhir" );
$idsyif_baru = odbc_result( $RSTList, "idsyif_baru" );
$id = odbc_result ($RSTList, "id");
$syif_nama = odbc_result ($RSTList, "ss_name");

$trkh_disp_start = "$tarikh_mula";
$dd_date = substr( $trkh_disp_start, 8, 2 );
$mm_date = substr( $trkh_disp_start, 5, 2 );
$yy_date = substr( $trkh_disp_start, 0, 4 );
$trkh_start = "{$dd_date}-{$mm_date}-{$yy_date}";
$trkh_start_date = "{$trkh_start}";
####################################################################
$trkh_disp_end = "$tarikh_akhir";
$dd_date = substr( $trkh_disp_end, 8, 2 );
$mm_date = substr( $trkh_disp_end, 5, 2 );
$yy_date = substr($trkh_disp_end, 0, 4 );
$trkh_end = "{$dd_date}-{$mm_date}-{$yy_date}";
$trkh_end_date = "{$trkh_end}";


?>
<tr>
<td><div align="center"><?php echo $int++; ?><input type="hidden" value="<?php echo $id; ?>" name="idbaru" /></div></td>
<td><div align="center"><?php echo $trkh_start_date; ?></div></td>
<td><div align="center"><?php echo $trkh_end_date; ?></div></td>
<td><div align="center"><?php echo $syif_nama; ?></div></td>
<td><div align="center"><a href="index.php?action=del&id=<?php echo $id; ?>">Padam</a></div></td>
</tr><?php } ?>
</table>

</p>
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>

mln_ndh
02-01-2012, 10:17 AM
Well i hope you understand my question and coding. Thanks :)

devnull69
02-01-2012, 11:06 AM
I'm sorry but the is NO call to del.php in your code



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum