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

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
evibesmusicAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
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
evibesmusicAuthor Commented:
@leakim971:

Using your code the confirm() dialog does not appear and the value is not replaced into the input?
0
leakim971PluritechnicianCommented:
miss a "backup." in the alert...
code updated : http://jsfiddle.net/8cq3nopu/18/
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

evibesmusicAuthor Commented:
@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
leakim971PluritechnicianCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
evibesmusicAuthor Commented:
@leakim971:

Perfect! Thank you so much!
0
evibesmusicAuthor Commented:
@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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.