JavaScript - any way to cancel SELECT onChange

Asked By Jim Tanner on 02-Aug-05 02:54 PM
i have a SELECT box and i have JS wired to the onChange event.
for example, suppose my select has 2 options  {A,B,C,D}.
Is this possible:
if the user currently has A selected, when they select B, is it possible to cancel the change and revert back to A?

I think u can do it

Asked By Bharath Reddy on 02-Aug-05 03:42 PM
Once u get the value in the on change event get the index of the value for which u want to be selected like in ur case now is A so get the index of that and change the selected index to = to what ever A has...

You can do this

Asked By Aarthi Saravanakumar on 02-Aug-05 03:43 PM
function fnCheck()
		{
			if(document.Form1.sel1.selectedIndex==0)
			{
			alert("here");
			document.Form1.sel1.selectedIndex=1;
			}
		}
Here I am not allowing the user to select Index 0. And hardcoding it to 1. Instead to go to the last selection, you can store the last selection in a hidden varaiable and always force that value.
Of course you would be displaying a better message than the "here" i have used.

store the last selected value

Asked By Abhinav gujjar on 04-Aug-05 10:52 AM
i think if your major concern is also reverting back to the exact value selected then on every selectchange event ,store the selcted value in an hidden element.
so when the user next shifts to an unacceptable value, set the drop down box to the last correct value.
any way to cancel SELECT onChange
Raj N replied to Jim Tanner on 20-May-09 12:08 PM
I hope this is solution would help you for the problem you mentioned

http://blogs.unbolt.net/index.php/brinley/2008/11/24/undo-a-html-select-box-selection

Thanks
Raj