Select input by value?

I have a bunch of hidden entrances on the page ...

<input type='hidden' name='thing' value='' />;
<input type='hidden' name='thing' value='' />;
<input type='hidden' name='thing' value='' />;

Etc ...

Each input can have any value.

In jquery, what is the best way to check if one of these inputs is set to a known specific value?

thank

+1
source share
3 answers

If you know that a specific value is specified for the value attribute, you can use the attribute selector

$('input[value="something"]');

http://api.jquery.com/category/selectors/

Edit to add:

you may need to bind the attr selector as input[name="thing"][value="something"], and @Drackir is right, you can check if it matches one or more elements using the lengthmatch property .

+4
source
$('input[type="hidden"][value="5084405"]');

hope this helps

+1
source

Below I propose the following. You want to look at all the items with a name and check them and do something for each suitable one.

$('input[name="thing"]').each(function() {
      var itemValue = this.val();
      if(itemValue == "X" || itemValue == "Y")
        alert("Item value is " + itemValue);
    });
0
source

All Articles