Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to append original value to input if confirmation dialog is denied?

Posted on 2014-08-21
7
Medium Priority
?
192 Views
Last Modified: 2014-09-02
Experts,

My script uses a confirm() dialog to alert the user when they have modified the value of an input.

If the confirmation is accepted, I want the script to execute an AJAX call. Which it does successfully.

If the confirmation is denied, I want to append the original value of the input to itself.

The append action is not executing when the user denies the confirmation dialog.

Any suggestions?

JSFiddle
0
Comment
Question by:evibesmusic
  • 4
  • 3
7 Comments
 
LVL 83

Expert Comment

by:leakim971
ID: 40278677
try this : http://jsfiddle.net/8cq3nopu/14/

$(".update_needs_table").change(function(e) {
    var backup = {
        site:$(this).attr("site"),
        department:$(this).attr("department"),
        userclass:$(this).attr("userclass"),
        input_number:$(this).attr("input_number"),
        original_value:$(this).attr("original_value")
    };
	var accept = confirm("You are about to update the needs for:\n\n-> Site: "+backup.site+"\n\n-> Department: "+backup.department+"\n\n->Employee Classification: "+userclass+"\n\nPlease confirm you would like to make this change.");
	if(accept){
		$("#input_div"+backup.input_number).load("./scripts/ajax_actions.php?ajax_post=update_needs", { 
			JobSite: backup.site,
			JobDepartment: backup.department,
			UserField13: backup.userclass,
			OriginalValue: backup.original_value,
			NewValue: $(this).val()
			}
		);			
	}
	else{
		//alert("User denied the confirmation dialog.");
        //THE STATEMENT ABOVE WORKS
        //HOW CAN I APPEND THE ORIGINAL DATA TO THE INPUT
        var input_number = backup.input_number
        for(var i in backup) {
            $("#input_number"+input_number).attr(i, backup[i]);
        }
	}
});//END .update_status FUNCTION

Open in new window

0
 

Author Comment

by:evibesmusic
ID: 40279250
@leakim971:

Using your code the confirm() dialog does not appear and the value is not replaced into the input?
0
 
LVL 83

Expert Comment

by:leakim971
ID: 40279306
miss a "backup." in the alert...
code updated : http://jsfiddle.net/8cq3nopu/18/
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!

 

Author Comment

by:evibesmusic
ID: 40279518
@leakim971:

Thank you.

That solves the confirm() dialog problem but, the original value of the input is still not placed into the input if the dialog is denied?
0
 
LVL 83

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 40279526
0
 

Author Comment

by:evibesmusic
ID: 40279680
@leakim971:

Perfect! Thank you so much!
0
 

Author Comment

by:evibesmusic
ID: 40300226
@all:

Here is another way to do it.

http://jsfiddle.net/8cq3nopu/28/

This method worked for me when serving pages via AJAX using jQuery UI Tabs.

The accepted solution worked within the Fiddle. When I tried to call this function by loading a page via AJAX in the jQuery UI Tab I would get "initialization" errors.

Each solution is valid and working.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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
Course of the Month21 days, 3 hours left to enroll

810 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