Solved

Confirm delete with OnClick

Posted on 2003-11-12
8
1,767 Views
Last Modified: 2008-03-06
Hello all.

I have an app in which the user can click "Delete" to delete a record from a database.  When clicked, I want to confirm from the user.  Being a novice JS programmer, I can't get it to work.  I'm sure it will be easy for you experts out there.  Here's how I'm trying to do it:

<a href="ddGalDelete.asp?galItem=<%=rsGallery("galItemID")%>" title="Delete This Listing" onClick="Confirm('Are you sure that you want to delete this item?')";>Delete</a>

As a bonus question, can anyone tell me why 'alert' works here:
<a href="ddGalDelete.asp?galItem=<%=rsGallery("galItemID")%>" title="Delete This Listing" onClick="Alert('Are you sure that you want to delete this item?')";>Delete</a>
0
Comment
Question by:knottydrd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 

Author Comment

by:knottydrd
ID: 9734244
Oh, I also want to cancel the event if the user chooses cancel.
0
 
LVL 10

Expert Comment

by:Bustarooms
ID: 9734334
<a href="ddGalDelete.asp?galItem=<%=rsGallery("galItemID")%>" title="Delete This Listing" onClick="if(!confirm('Are you sure that you want to delete this item?'))return false;">Delete</a>


Alert will not work because Javascript is case sensitive...the proper format for an alert is alert('what do you want to say');

you had the same problem with your confirm()
0
 

Author Comment

by:knottydrd
ID: 9734429
Thanks

I switched to this:

<script type="text/javascript">
     function ConfirmDelete(){
         var confDel = confirm("Enter some information")
     }
</script>

            <span class="tableLinks"><a href="ddGalDelete.asp?galItem=<%=rsGallery("galItemID")%>" title="Delete This Listing" onClick='ConfirmDelete()'";>Delete</a>


How do I cancel the click if the user chooses "Cancel" on the confirm box?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Accepted Solution

by:
Bustarooms earned 100 total points
ID: 9734442
<script type="text/javascript">
     function ConfirmDelete(){
         var confDel = confirm("Enter some information")
         return confDel
     }
</script>

          <span class="tableLinks"><a href="ddGalDelete.asp?galItem=<%=rsGallery("galItemID")%>" title="Delete This Listing" onClick='return ConfirmDelete()'";>Delete</a>
0
 
LVL 2

Expert Comment

by:_DanElliott
ID: 9734459
Change it to

<span class="tableLinks"><a href="ddGalDelete.asp?galItem=<%=rsGallery("galItemID")%>" title="Delete This Listing" onClick='return ConfirmDelete()'";>Delete</a>

Add "return" to the onClick
0
 

Author Comment

by:knottydrd
ID: 9734463
Awesome, here's 100 points.  Thanks a lot!
0
 
LVL 10

Expert Comment

by:Bustarooms
ID: 9734470
no problem
0
 
LVL 1

Expert Comment

by:oktexasguy
ID: 9734549
knottydrd-
Try this out.  It uses a different method for page forwarding but will do exactly what you are trying to do above.

<script type="text/javascript">
function ConfirmDelete(objectId){
    if( confirm("Are you sure you want to delete?") ){
        var newLoc = "ddGalDelete.asp?galItem=" + objectId
        window.location = newLoc;
    }
}
</script>

<a href="javascript:ConfirmDelete('<%=rsGallery("galItemID")%>');" title="Delete This Listing">Delete</a>
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question