Page 1 of 1
Delete Are you sure
Posted: Tue Aug 01, 2006 5:05 am
by mohson
Hi can anyone show me how to update this code so that when usere clicks delete a pop up box appears saying "Are you sure you want to delete"
The code below with help form someone on this site allowed me to insert a message when a record was added
Code: Select all
previously ive used 'New Record added" <?php
if ((isset($_GET['Sent'])) and ($_GET['Sent'] == 'true')) { echo '<b>New Person Added, Add Another?</b>'; }
?>
Which returns the message above, this is fine for informing users that a record has been added BUT when users delete you would probably prefare to have a pop up saying Delete are you Sure? OK/CANCEL
Any help would be much appreciated
Posted: Tue Aug 01, 2006 5:26 am
by shiznatix
javascript is what you are looking for. i don't know much JS but you want the confirm() function. google for that and you will find answers (first hit for 'javascript confirm' is dandy)
Posted: Tue Aug 01, 2006 6:08 am
by Jenk
Code: Select all
<script language="javascript">
function checkit(form)
{
var answer = confirm('Are you sure?');
if (answer) {
form.submit();
} else {
return false;
}
}
</script>
<form name="myform" action="" method="post" onSubmit="checkit(this)">
<input type="submit" value="click.." />
</form>
Posted: Tue Aug 01, 2006 6:28 am
by CoderGoblin
OK I know virtually everybody actually has javascript but what about those who don't... Some form of fallback may be necessary...
Also you could potentially use a tooltip solution to avoid the ugly javascript confirm.
possible tooltip extension at
http://www.walterzorn.com/tooltip/tooltip_e.htm but I know there are many others.
Posted: Tue Aug 01, 2006 6:42 am
by mohson
Looking through the posts on this forum I found this code for confirming delete
Code: Select all
<form action='deleterecord.php' method='POST' onsubmit='return confirm("Are you sure?");'>
<input type='hidden' name='id' value='123' />
<input type='submit' name='delete' value='Delete record' />
</form>
Also the one suggested above
I get the impression that this refers to a process page, my code does not link to a process page. It processes within the page.
So can someone show me how to do this delete are you sure within the same file?
Also I have 2 submit buttons one for save and one for delete.
how will I apply the javascript to the submit which links to the Delete submit and not the save submit?
My code for both save and delete are below:
Save
Code: Select all
if(isset($_GET['org_id'])){
$org_id=$_GET['org_id'];
}
if ($_POST['Submit'] == 'Save'){
foreach ($_POST as $formName => $phpName){
$$formName = $phpName;
}
Delete
Code: Select all
}
if ($_POST['action'] == "Delete Record"){
$delete = mysql_query("DELETE FROM organisations WHERE org_id = '$org_id'") or die(mysql_error()); }
echo "<form action=\"editorganisations.html?org_id=$org_id\" method=\"post\">
<input type=\"hidden\" name=\"action\" value=\"Delete Record\">
<input type=\"submit\" value=\"Delete Record\">
</form>
</td><p>";
Any help much appreciated.
Posted: Tue Aug 01, 2006 6:51 am
by JayBird
Please dont double post
