dlcnet
asked on
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?
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.
Make a printout when you done.
ASKER
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.
post a link to your page.
ASKER
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>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
A A++++ solution