Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Confirm delete with OnClick

Posted on 2003-11-12
8
Medium Priority
?
1,779 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
LVL 10

Accepted Solution

by:
Bustarooms earned 400 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one 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…

688 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