Forum Moderators: open
this might be a very stupid question so I apologise in advance. I want to create an alert box for an admin site that I have taken over for a client.
Im new to ASP so huge learning curve ahead of me. The problem is on the admin page they have a delete button which goes ahead and deletes all the info. What I want to do is put an alert box inbetween the link and the deleting function.
example
press delete - up pops alert 'do you want to delete' - press ok - info gets deleted.
what I can't get my head around is how I write the code. The scripts that I've been looking at look really simple and easy and work great but where do I put the code for deleting the info selected. The reason I ask this is because the ASP code that deletes the info is in the link on the admin page and I am getting a bit lost as to what direction to take.
below is an example of a code that I wish to use for the alert box.
function confirm_entry()
{
input_box=confirm("Click OK or Cancel to Continue");
if (input_box==true)
{
// Output when OK is clicked
alert ("You clicked OK");
}
else
{
// Output when Cancel is clicked
alert ("You clicked cancel");
}
}
-->
</script>
Click <a href="JavaScript:confirm_entry()">here</a>
<p>
<form onSubmit="confirm_entry()">
<input type="submit" >
</form>
here is the code that is telling the link to delete the info from the database
<A HREF="altlist.asp?action=delete&actionid=<%=admin.fields.item("id")%>" onMouseOver="MM_callJS('sethelptext(\'DELETE this item from the database\')')" onMouseOut="MM_callJS('clearhelptext()')">
How do I put these two functions together.....hope you can help
Thanks
<form method="get" action="altlist.asp" onSubmit="return confirm_entry()">
<input type="submit" name="Submit" value="Delete Now">
<input type="hidden" name="action" value="delete">
<input type="hidden" name="actionid" value="<% =admin.fields.item("id") %>">
</form>
Should work. If you think of the asp code and javascript (not java) as completely separate it helps.
Here, this asp page submits its form to altlist.asp (which will have the delete code). Then added onto this is the javascript function that prompts the user and then either returns true (so the form is submitted, and hence the record deleted) or false (so the form submit is cancelled - nothing happens).
I have defined the java function and have placed this at the top of my page with my other java functions.
}
function confirm_delete(){
var user_input = confirm("You have chosen to completely delete this info. Continue?");
if (user_input == true) {
return true;
} else {
return false;
}
I have then created a graphic of a delete button and have attached the code written below to it.
<DIV ALIGN="center"><A HREF="altlist.asp?action=delete&actionid=<%=admin.fields.item("id")%>" onMouseOver="MM_callJS('sethelptext(\'DELETE this item from the database\')')" onMouseDown="MM_callJS('confirm_delete()')" onMouseOut="MM_callJS('clearhelptext()')" ><IMG SRC="../images/bin.gif" WIDTH="15" HEIGHT="16" BORDER="0"></A></DIV>
With my limited experience I thought that it was telling the user that when the scroll over the button it tells text to change elsewhere on the page.....when you roll out of the delete button the text should change back and when you click on the button you should get my pop-up box asking if you want to delete the information.
I don't get this.....when I click on my delete button it just goes ahead and deletes the info. I want the pop-up box to appear and them to confirm deletion.
Can someone help me out here.....what am I missing.
Thanks a lot :-)
Try placing javascript alerts first on your mousedown, then at the top of your function to trace where the code dies.
Also, this type of thing is normally implemented with an OnClick instead of a mouseDown, but that's just preference I suppose.
Ross
So your div, assuming you've fixed other probs as above, will be:
<DIV ALIGN="center"><A HREF="altlist.asp?action=delete&actionid=<%=admin.fields.item("id")%>" onMouseOver="MM_callJS('sethelptext(\'DELETE this item from the database\')')" onClick="return confirm_entry()" onMouseOut="MM_callJS('clearhelptext()')" ><IMG SRC="../images/bin.gif" WIDTH="15" HEIGHT="16" BORDER="0"></A></DIV>
Hope this works :)