[thelist] Triggering an alert box

Burhan Khalid thelist at meidomus.com
Sun Mar 27 00:36:11 CST 2005


Chris Kavanagh wrote:
> Hola list,
> 
> Thank the goddesses for illegal stimulants!  Coffee alone would never 
> have kept me trucking this long.  I am coding, but I can't feel my face.
> 
> To business: I have an <A HREF> on my intranet site that deletes an 
> entry in the backend database.  The deletion can't be undone, so it 
> might be nice to have an alert box that warns of such before actually 
> completing the action.  What's the best way to do this?  I'm using 
> ColdFusion, but maybe the best solution is JavaScript?

I'm not familiar with coldfusion, but if its anything like PHP, you 
cannot trigger an alert box with it, so your only hope is javascript.

Note that with an alert, the user cannot choose a cancel action, so you 
might want to change it to a confirm box, which the user can hit Okay or 
Cancel on.

What you can do is, change your link target to a javascript function, 
which pops up the confirm.  If the response from the alert is okay, 
true, positive (you can check for this), then you can redirect to the 
delete page, if not, just end the function; the browser should stay on 
the same page.

Some very crude Javascript (probably doesn't work):

<script language="javascript">
function delete_record()
{
    if (confirm("Delete the record?"))
    {
       document.location.href = 'delete.cfm?id=12';
    }
}
</script>

<span onclick="delete_record();" style="cursor:hand;">delete record</span>

Hope this helps



More information about the thelist mailing list