soy más de una persona PHP, JS no - y creo que mi problema es más un problema de sintaxis ..JS jQuery - comprobar si el valor está en serie
Tengo una pequeña jQuery para "validar" y cheque valor de entrada .
Funciona bien para palabras sueltas, pero necesito una matriz.
Estoy usando el inArray()
de jQuery.
var ar = ["value1", "value2", "value3", "value4"]; // ETC...
jQuery(document).ready(function() {
jQuery("form#searchreport").submit(function() {
if (jQuery.inArray(jQuery("input:first"), ar)){
//if (jQuery("input:first").val() == "value11") { // works for single words
jQuery("#divResult").html("<span>VALUE FOUND</span>").show();
jQuery("#contentresults").delay(800).show("slow");
return false;
}
// SINGLE VALUE SPECIAL CASE/Value not allowed
if (jQuery("input:first").val() == "word10") {
jQuery("#divResult").html("YOU CHEAT !").show();
jQuery("#contentresults").delay(800).show("slow");
return false;
}
// Value not Valid
jQuery("#divResult").text("Not valid!").show().fadeOut(1000);
return false;
});
});
ahora - este if (jQuery.inArray(jQuery("input:first"), ar))
no está funcionando bien .. todos los valores que puse será validado como OK. (incluso vacío)
Necesito validar solo valores de la matriz (ar).
me trataron también if (jQuery.inArray(jQuery("input:first"), ar) == 1) // 1,0,-1 tried all
lo que estoy haciendo mal?
Pregunta extra: cómo hacerlo NO en el array en jQuery ?? (el equivalente de PHP if (!in_array('1', $a))
- Me SW somehre que no va a funcionar, y la necesidad de usar algo como esto:. !!~
'$ .inArray (. ..) == -1' <----- no existe tal elemento en una matriz – zerkms