This is a pretty simple way to do this ... Use change / input and when it is focused, reset the text to what it is up to a year.
Appears to work well in all browsers I tested. The problem is that no matter what you do, you always have to change the text value of the selected item, there is no way around this. Test yourself without deployment here - http://jsfiddle.net/CTwJy/
<select name="month_selection" id="month_selection"> <optgroup label="2012"> <option value="1">January</option> </optgroup> <optgroup label="2011"> <option value="1">January</option> <option value="2">February</option> </optgroup> </select> <script type="text/javascript"> function attach(ele, evt, cb) { ele.addEventListener ? ele.addEventListener(evt, cb) : ele.attachEvent('on' + evt, cb); } function evSupported(ele, evt) { return ((('on'+evt) in ele) ? true : (function(ele, evt) { ele.setAttribute('on'+evt, 'return;'); return (typeof ele['on'+evt] == 'function'); })()); }; var selectBox = document.getElementById('month_selection'); attach(selectBox, (evSupported(selectBox, 'input') ? 'input' : 'change'), function() { this.options[this.selectedIndex].innerText += ' ' + this.options[this.selectedIndex].parentNode.label; this.blur(); }); attach(selectBox, 'focus', function() { for (var i = 0; i < this.options.length; i++) { this.options[i].innerText = this.options[i].innerText.split(' ')[0]; } }); </script>
source share