How do I restore a previous selected option on confirm dialog


Hi Experts!

I have the following problem. I have a drop-down option with a confirm dialog. When a user selects a particular value a confirm dialog pops.  However when I click cancel the value of the drop-down is not reseted to the previous user selected, it is just the new value.
Is there any way to "remember" the previous value and set it back when the user click Cancel?
dlcnetAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

hieloCommented:
at load time, save the "default" value onto a global variable. Upon selection change, update update that variable only if user does not cancel. So when the dialog is dismissed by cancelling, then use use the value in that variable to reset to the previous selection.
0
AveshCommented:
Make a printout when you done.
0
dlcnetAuthor Commented:

Hi Hielo

I tried that. However my drop-down has 25 options and only 1 has the confirm dialog. At any change the "global variable" is updated with the new value selected.
0
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

hieloCommented:
post a link to your page.
0
dlcnetAuthor Commented:

Hi!

The code I posted bellow. When the user selects nothing then the confirm dialog comes. However I would like when he No/ Cancel chooses to "remember" the previous selection that the user had and "restore" it
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<script type="text/javascript" src="lib/jquery/jquery-1.3.2.js"></script>

        <title>New Web Project</title>
    </head>
    <body>
        <h3>New Web Project Page</h3>
		
		<select id="dropDown1">
			<option value=""></option>
			<option value="1">Option1</option>
			<option value="2">Option2</option>
			<option value="3">Option3</option>
			<option value="4">Option4</option>
			
		</select>
		
		<script type="text/javascript">
			
			jQuery(function () {
				
				jQuery('#dropDown1').change(function () {
					var selectedValue = jQuery('#dropDown1').val();
					//alert(selectedValue);					
					
					var confirmText = "Do you want to proceed?";					
					if (selectedValue == "") {
						if (confirm(confirmText)) {
							jQuery('<a>jQuery</a>').attr('href', 'www.jquery.com').appendTo('body');		
						} else {
							return none;
						}
					}				
				})				
			});
			
		</script>
		
    </body>
</html>

Open in new window

0
hieloCommented:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>

        <title>New Web Project</title>
    </head>
    <body>
        <h3>New Web Project Page</h3>
                
                <select id="dropDown1">
                        <option value=""></option>
                        <option value="1">Option1</option>
                        <option value="2">Option2</option>
                        <option value="3">Option3</option>
                        <option value="4">Option4</option>
                        
                </select>
                
                <script type="text/javascript">
                        var selectedValue=0;
                        jQuery(function () {
                                
                                jQuery('#dropDown1').change(function () {
                                        //var selectedValue = jQuery('#dropDown1').val();
                                        //alert(selectedValue);                                 
                                        
                                        var confirmText = "Do you want to proceed?";                                    
                                        if ( jQuery('#dropDown1 option:selected').val() == "") {
                                                if (confirm(confirmText)) {
                                                        jQuery('<a>jQuery</a>').attr('href', 'www.jquery.com').appendTo('body');                
                                                } else {
                                                        this.selectedIndex=selectedValue;
											 return false;
                                                }
                                        }
								else
								{
									   selectedValue = jQuery('#dropDown1 option').index($('#dropDown1 option:selected'));
								}
                                })                              
                        });
                        
                </script>
                
    </body>
</html>

Open in new window

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
dlcnetAuthor Commented:
A A++++ solution
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.