Jquery Check Value

Asked

Viewed 606 times

1

I have a dynamic form with various Hidden inputs and wanted to check by jquery if there is one that has a certain value in value is possible?

2 answers

4


Good morning Thepeter,

What the code I am entering will do is, in all Hidden inputs find the value of the inputs and compare with the closed value (compare_value variable). I think this is what you want.

var compare_value = 10; // Exemplo de valor a validar.

$("input:hidden").each(function(){ // Loop todas as inputs hiddens
    if(this.value == compare_value){ // comparar o valor da input e o valor defenido antes
    // Caso a afirmação seja verdadeira do something
    }
});

Regards.

3

If the value is dynamic, that is it has been changed relative to what is in the HTML attribute, then you have to iterate the inputs and filter what has the value you are looking for.

Something like that:

var encontrados = $('input:hidden').filter(function(){
    return this.value == valorEsperado;
});

and then you can use encontrados.length if you want to know if there are any, or just use the element(s) in other operations, for example:

encontrados.show();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.