Jump to content

How to select option if value is 'exactly' the string?


Go to solution Solved by Barand,

Recommended Posts

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....?

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>

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.