Hide Option Select Value Based On Option Value Selected On First Options April 21, 2024 Post a Comment I have two select option field. TypeSolution 1: You can use jquery$(document).ready(function(){ $('#ostatus').on('change',function() { if($(this).val()== 'Ghost'){ $('#oupg') .find ("option[value=Retail]").hide(); $('#oupg') .find ("option[value=Prepaid]").hide(); } else{ $('#oupg') .find ("option[value=Retail]").show(); $('#oupg') .find ("option[value=Prepaid]").show(); } }); }); CopySolution 2: Using Javascript and display:none css styling you can accomplish this:<head><scripttype="text/javascript">functionhideOpt() { var type = document.getElementById("ostatus"); var upgrade = document.getElementById("oupg"); if (type.options[type.selectedIndex].value == 'Ghost') { upgrade.options[3].style.display = 'none'; upgrade.options[4].style.display = 'none'; // IE exception upgrade.options[3].disabled = true; upgrade.options[4].disabled = true; } else { upgrade.options[3].style.display = 'block'; upgrade.options[4].style.display = 'block'; // IE exception upgrade.options[3].disabled = false; upgrade.options[4].disabled = false; } } </script></head><label>Type</label><selectname="ostatus"id="ostatus"onchange="return hideOpt();"class="input-small"><optionvalue="Actual">Actual</option><optionvalue="Ghost">Ghost</option></select><label>Upgrade</label><selectname="oupg"id="oupg"class="input-small"><optionvalue="Exp" >Exp</option><optionvalue="Post" >Post</option><optionvalue="Upgrade" >Upg</option><optionvalue="Retail" >Retail</option><optionvalue="Prepaid" >Prepaid</option></select>CopyEdit:Added else statement to show the options again when 'Actual' is selected.Solution 3: You can't hide option elements in all browsers, but you can disable them:document.querySelector("#oupg option[value=Retail]").disabled = true; document.querySelector("#oupg option[value=Prepaid]").disabled = true; CopyThis will work in IE8 and up.If you want IE7 and lower support, then:var opts = document.getElementById("oupg").options; opts[opts.length - 2].disabled = true; opts[opts.length - 1].disabled = true; Copy Share Post a Comment for "Hide Option Select Value Based On Option Value Selected On First Options" 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