Rewriting confirmation box from javascript to jquery

Posted on 2009-12-29
Medium Priority
Last Modified: 2012-06-21
Dear experts,

Below is a simple confirmation box done in javascript.

- An example with and without an "else"-statement.
- An example that only affects the button, not the whole form.
- An example that redirects to a specified page (like in window.location)

I'm changing all my javascript into jquery, so how do I rewrite this piece into jQuery?

Library: <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js'></script>

<input type="button" onclick="confirmation()" value="Delete record" />

<script type="text/javascript">
function confirmation() {
    var answer = confirm("WARNING: The record will be deleted permanently. Continue?")
    if (answer){
        window.location = "deleterecord.asp?id=<%= rs("id") %>";
        alert("Record not deleted.")

Open in new window

Question by:DanishCoder
LVL 22

Accepted Solution

kadaba earned 1000 total points
ID: 26143005
few things remain same.. hope this helps.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
  <script src="http://code.jquery.com/jquery-latest.js"></script>
  <script type="text/javascript">
    $("#deleteButton").click(function () { 
      var answer = confirm("WARNING: The record will be deleted permanently. Continue?")
		if (answer){
			window.location = "http://www.google.com";
			alert("Record not deleted.");

	$("#deleteButton1").click(function () { 
      var answer = confirm("WARNING: The record will be deleted permanently. Continue?")
		if (!answer){
			alert("Record not deleted.");
		window.location = "http://www.google.com";
	<input type="button" id="deleteButton" value="Delete Record 1">
	<input type="button" id="deleteButton1" value="Delete Record 2">

Open in new window


Author Closing Comment

ID: 31670999
Thx Kadaba! I deletede the else-statement in line 13-15 to fit my needs.
Thought it could be done much easier in jQuery than "almost the same" ;-)
Happy New Year!

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This article discusses how to implement server side field validation and display customized error messages to the client.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

864 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