Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

155
Vistas
why is this not validating select?

I want to validate my form that includes inputs, and one select , but at the moment when I want to validate does not works with my select , how can I do it or edit my code to validate all together, but I am having problems with it . any ideas.

$("#form1").submit(function(e){
e.preventDefault();
var letters1=/^[A-Za-z]+$/;
var letters2 = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
var email=  document.getElementById("email").value;
var password=  document.getElementById("password").value;
var fname=document.getElementById("fname").value;
var lname=document.getElementById("lname").value;
var selectUser=document.getElementById("user");
var valid=selectUser.value=="select user";

if(email.length>0 && email.match(letters2))
{
    if(password.length>0)
    {
        if(fname.length>0&&fname.match(letters1))
        {
            if(lname.length>0&&lname.match(letters1))
            {
                if(selectUser.invalid)
                {
                    alert('please enter user');
                    selectUser.className='error';
                }
                else{
                selectUser.className='';
                }
            }
            else{
                alert("wrong last");
            }
        }
        else{
                alert("wrong first");
            }
    }
    else{   
                document.getElementById("password").style.borderColor="red";
                alert("wrong password");
            }
}
else{
                alert("wrong email");
            }

return !invalid;})

html

<select id="user" name="user">
                <option value="select user">select user</option>
                <option>Admin </option>
                <option> SuperAdmin</option>
                <option> Staff</option>
            </select>
            <div class="submitbtn">
            <a href="#submit1">
                <button type="submit">Submit</button></div>
            </a>
        </div>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You have declared a variable with the name ‘valid’. But you are not using it.

You should check ‘valid’ instead of ‘selectUser.invalid’.

Also the condition for ‘valid’ should be the opposite: The select’s value should not be ‘select user’

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda