QUIERO COMPARAR EL CONTENIDO DE UN select!!!!! NO ESTOY COMPARANDO EL VALOR DEL select
tengo este codigo y quiero validar que $(this).val() == linea
pero tengo que cambiar $(this).val()
por $(this).text()
para poder hacer la comparacion pero no me funciona me sale en blanco y con val()
si me arroja el valor pero quiero comparar el contenido del campo en lugar del valor
$("input[name='lineas']").each(function(i, obj) {
console.log($(this).text());
if($(this).val() == linea){
repetido = 1;
}
});
// con este obtenego el valor
$(this).val()
// con este deberia obtener el texto que esta en el input (pero no funciona)
$(this).text()
La solución puede ser en jquery o javascript no hay problema.
ya intente esto
$("input[name='lineas']").each(function(i, obj) {
console.log($('select[name="lineas"] option:selected').text());
if($('select[name="lineas"] option:selected').text() === linea){
repetido = 1;
}
})
;
// tambien intente esto
$("input[name='lineas']").each(function(i, obj) {
console.log($(this).text());
if($(this).val().text() === linea){
repetido = 1;
}
});
// mi solucion fue comparar el id $("input[name='lineas']").each(function(i, obj) { if($(this).val() === idLinea){ repetido = 1; } });
.text()
? Estás equivocado... Se obtiene con.val()
, tal cual estás diciendo en tu pregunta. Y sin jQuery,tuInput.value
.