?
Solved

Rewriting confirmation box from javascript to jquery

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

Below is a simple confirmation box done in javascript.

Requirements:
- 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>

Thanks,
DanishCoder
<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") %>";
    }
    else{
        alert("Record not deleted.")
    }
}
</script>

Open in new window

0
Comment
Question by:DanishCoder
2 Comments
 
LVL 22

Accepted Solution

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

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

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

Open in new window

0
 

Author Closing Comment

by:DanishCoder
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!
0

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