/* Brian Hendel. This script simulate the "disabled" functionality of select options in IE, similar to what we get on Firefox. */ //In order to keep the window's current onLoad (to not overwrite), we need to use the event functions. Use different functions for IE and other if (window.addEventListener){ window.addEventListener("load", new Function(window.onload), true); window.addEventListener("load", simulate_option_disabled, true); } else if (window.attachEvent){ window.attachEvent("onload", simulate_option_disabled); } function simulate_option_disabled() { if (document.getElementsByTagName) { var s = document.getElementsByTagName("select"); if (s.length > 0) { for (var i=0, select; select = s[i]; i++) { // If there is already an onChange event in this select box, we need to keep it if(select.onchange == null) select.onchange = new Function("if(this.options[this.selectedIndex].disabled==true){ this.selectedIndex=0; alert('Please note that this value is not accepted.');}"); else { // Since we're going to be overwriting the old onChange, we need to add it as a function using the new method. Here we // also check which function the browser supports, and use the appropriate one. if (select.addEventListener){ select.addEventListener("change", new Function(select.onChange), true); select.addEventListener("change", new Function("if(this.options[this.selectedIndex].disabled==true){ this.selectedIndex=0; alert('Please note that this value is not accepted.');}"), true); } else if (select.attachEvent){ select.attachEvent("onchange", new Function("if(window.event.srcElement.options[window.event.srcElement.selectedIndex].disabled==true){window.event.srcElement.selectedIndex=0; alert('Please note that this value is not accepted.');}")); } } // Now, for each select, lets loop over each option, and gray out those that have been defined as disabled for (var j=0, option; option = select.options[j]; j++) { if (option.disabled) { option.style.color = "graytext"; } else { //option.style.color = "menutext"; } } } } } }