Jquery Check Value

1

I have a dynamic form with several hidden inputs and wanted to check by jquery if any one has a certain value in the value is possible?

    
asked by anonymous 16.10.2015 / 11:12

2 answers

4

Good morning Thepeter,

What the code I'm going to do is, in all the hidden inputs, look for the value of the same and compare with the value defined (variable compare_value). I think that's 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.

    
16.10.2015 / 11:46
3

If the value is dynamic, that is, it has been changed in relation 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 this:

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

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();
    
16.10.2015 / 11:29