Javascript confirm delete

JavaScript and client side scripting.

Moderator: General Moderators

User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Code: Select all

<input type=\"button\" value=\"Delete Record\" onClick="checkit('formname')">
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

Ok,

Ive put

Code: Select all

<?php include "dyn.header"; ?>
<!-- Please don't remove these comments -->
<!-- Content Start -->

<script language="javascript"> 
function checkit(form) 
{ 
    var answer = confirm('Are you sure?'); 

    if (answer) { 
        form.submit(); 
    } else { 
        return false; 
    } 
} 
</script>
This at the top of my page and Ive changed the delete cde to this:

Code: Select all

echo "<form action=\"editorganisations.html?org_id=$org_id\" method=\"post\">
<input type=\"hidden\" name=\"action\" value=\"Delete Record\">
<input type=\"button\" value=\"Delete Record\" onClick="checkit('formname')"> 
</form>
BUt nothing happens
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Come on, think about it.

Hmmm...what is your form called :hint:
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

infact, i would probably do it like this

Code: Select all

<script language="javascript"> 
function checkit() 
{ 
    var answer = confirm('Are you sure?'); 

    if (answer) { 
        return true;
    } else { 
        return false; 
    } 
} 
</script> 

Code: Select all

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\" onclick=\"checkit()\">
</form>
Last edited by JayBird on Thu Aug 03, 2006 6:00 am, edited 1 time in total.
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post by jmut »

Is it something complicated or as simple as:

Code: Select all

<form action='deleterecord.php' method='POST'>
 <input type='hidden' name='id' value='123' />
 <input type='submit' name='delete' value='Delete record' onclick="if(confirm('Are you sure?')) return true; else return false;" />
</form>
Edit: Sorry ..didn't see there is second page. both examples should work.
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

Ok Ive done it using Pimps method but one problem when you click cancel it still deletes the record?

Why is
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

put return in front of the function name. ie onclick="return function()"
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

sorry where do I put that?
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post by jmut »

mohson wrote:sorry where do I put that?


....
<input type="hidden" name="action" value="Delete Record">
<input type="submit" value="Delete Record" onclick="javascript: return checkit();">
</form>
Post Reply