simona6 Posted May 22, 2023 Share Posted May 22, 2023 0 <select> <option value="America">America</option> <option value="North America">North America</option> </select> We have an issue where in WP Forms we have a list of countries or regions, and we want to be able to disable any given one as a Parent, such as disabling "America" in the form above. IE. Europe, Great Britain, Spain. We'd like to disable Europe form being selected. <script type="text/javascript"> (function( $ ) { 'use strict'; $(document).ready( function(){ var $option = $('option:contains("America")'); $option.attr('disabled',true); }); })(jQuery) </script> I tried this, as I found it online, but the issue is that for North America, this tool will be disabled as the option "contains" America. Is there a different "contains" term to use, that means this "specifically and only" in the field....? Quote Link to comment https://forums.phpfreaks.com/topic/316331-how-to-select-option-if-value-is-exactly-the-string/ Share on other sites More sharing options...
Barand Posted May 22, 2023 Share Posted May 22, 2023 Equals? Quote Link to comment https://forums.phpfreaks.com/topic/316331-how-to-select-option-if-value-is-exactly-the-string/#findComment-1608571 Share on other sites More sharing options...
simona6 Posted May 22, 2023 Author Share Posted May 22, 2023 No that doesn't do anything. . Causes the field to be "normal" and selectable. <script type="text/javascript"> (function( $ ) { 'use strict'; $(document).ready( function(){ var $option = $('option:equals("America")'); $option.attr('disabled',true); }); })(jQuery) </script> Quote Link to comment https://forums.phpfreaks.com/topic/316331-how-to-select-option-if-value-is-exactly-the-string/#findComment-1608572 Share on other sites More sharing options...
Solution Barand Posted May 22, 2023 Solution Share Posted May 22, 2023 let $option = $("option[value='America']") $option.attr('disabled',true) Quote Link to comment https://forums.phpfreaks.com/topic/316331-how-to-select-option-if-value-is-exactly-the-string/#findComment-1608573 Share on other sites More sharing options...
simona6 Posted May 22, 2023 Author Share Posted May 22, 2023 Brilliant. Thank you. That's got it. Quote Link to comment https://forums.phpfreaks.com/topic/316331-how-to-select-option-if-value-is-exactly-the-string/#findComment-1608574 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.