Solved

Confirm delete with OnClick

Posted on 2003-11-12
8
1,748 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
Technology Partners: 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Suggested Solutions

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

740 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