Jquery Disable Option In Dropdown March 31, 2024 Post a Comment Guys i have used the following code to disable an option using jQuery (jquery-1.4.2.min).The disable happens in Firefox , but not in IE. Solution 1: I think i might be wrong but it could be because the select rather than option can be disabled. Since firefox is great and IE sucks, well you can guess why :) you having that problem. Use css to grey out the text of that option.then on jquery do something like this.$('#SCOPE').change(function(){ if($('#SCOPE option[value="'+$(this).val()+'"]').attr('disabled') == 'disabled'){ alert('Its disabled you cannot select this option'); } }); CopyBTW. double check the code as I have not tested this :)Solution 2: My take is bit different to other answers.The aim is not to hide the options but just make them disable(to keep the UI consistent).My Scenario :I have multiple selects in a form and when an user selects an option in one of the selects the other selects should disable this option and vice versa. User is restricted from selecting the same option which is already selected. We normally disable the option but for IE 7 which does not support it. User also gets an option to add new selects.Solution :On load :If the browser is IE7 then while populating the the selects and disabling the already selected options on other selects I am adding a custom attribute to the option("data-ie7-disabled") and also changing the color of the disabled options to '#cccccc'(which is the standard color for disabled options). This makes the UI look same across browsers.On Change :I save the previous option in a local variable(this is saved on focus).When a user tries to change an optionUser selects a complete new option which is not selected in any other dropdown. Then I loop through other selects and change the color and add custom attribute to this selected option on other selects.When user selects an option that is already selected(The option which has grayed out color). I check if the option has this custom attribute on it first. If it has then > I simply revert the option to the previous one with an error message saying "This option is already selected or BLAH BLAH".When user changes his existing option to a brand new option which is not selected in any other dropdown's. I again loop through all the other select options and remove the color on it and also the custom attribute.Hope this helps. Share Post a Comment for "Jquery Disable Option In Dropdown" Top Question Select Element Onmouseleave Event In Safari I want to catch the mouse leaving a select box with the cod… How To Dynamically Add An New Input Field On "keydown" Using JQuery? I want to have a new input field dynamically generated when… Input Type Datetime-local Is Not Working In Firefox I have an input type of datetime-local which is working fin… Block Scoping Of Let And For…of The let statement in ES2015 allows us to declare block scop… Reference Errors Thrown In Included File... Unless Calling File Includes Slow Code A funny thing happened to me while I was cleaning up some o… Getting Object Name From Inside The Class (JavaScript) I have a class and I want from inside the class to save as … Cannot Read Property 'getContext' Of Null I have a button which on click executes this function.This … What Are Alternatives To ExtJS? So what I'm looking for is a javascript framework I can… How Do I Use Data From Vue.js Child Component Within Parent Component? I have a form component where I use a child component. I wa… Call Multiple Ajax Request In Series Or Parallel I have 3 functions. load_graphs('national','… December 2024 (1) November 2024 (37) October 2024 (70) September 2024 (23) August 2024 (367) July 2024 (334) June 2024 (701) May 2024 (1297) April 2024 (807) March 2024 (1552) February 2024 (1717) January 2024 (1373) December 2023 (1452) November 2023 (421) October 2023 (593) September 2023 (302) August 2023 (343) July 2023 (270) June 2023 (370) May 2023 (215) April 2023 (132) March 2023 (152) February 2023 (181) January 2023 (286) December 2022 (131) November 2022 (239) October 2022 (164) September 2022 (169) August 2022 (505) July 2022 (313) June 2022 (269) Menu Halaman Statis Beranda © 2022 - JavaScript Gen