I am currently working with this JavaScript code:
function change(selection){
if(confirm("Select this option?"))
{
} else {
if(selection=="1")
{
alert("Return selected to NO");
} else {
alert("Return selected to YES");
}
}
}
Here is the corresponding HTML code snippet:
<select id="sel" name="sel" onchange="change(this.value)">
<option value="1">YES</option>
<option value="0">NO</option>
</select>
My Desired Outcome:
Assume that by default, the selected option is YES. If the user chooses to select NO, confirmation boxes will appear asking if they want to switch to NO or not. If they click "OK", then the NO option will be selected. However, if they click "CANCEL", no selection will be made and the YES option stays selected. The same process applies vice versa.
To see a live example, check out this Fiddle: http://jsfiddle.net/CtxUy/