Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

165
Visualizações
onblur working unexpectedly before I even select the input element

I have a select tag element for which I want to add a red box shadow onblur after validating the user input. For some reason the onblur() is being called if I click anywhere in the browser where its actually supposed to work after I select the element and later takes off the focus. This is my select element:

    <div class="form-group col-md-4">
      <select class="form-control" id="income">
        <option value="-1" class="select-option">
          Gross Annual Income
        </option>
        <option>100000</option>
        <option>200000</option>
        <option>300000</option>
        <option>500000</option>
      </select>
      <span class="error incomeError"></span>
    </div>

this is my validation

  function validateIncome(income) {
    if (income === '-1') {
      $('.incomeError').text('cant be empty');
      return false;
    } else {
      $('.incomeError').text('');
      return true;
    }
  }

My validate function is returning the right value. I'm only having trouble with the onblur which looks like:

   let userIncome = $('#income');
    userIncome.on('blur', function () {
      let userVal = $(this).val();
      if (!validateIncome(userVal)) {
        $(this).css({
          'box-shadow': '0px 0px 6px red',
        });
      } else {
        $(this).css({
          'box-shadow': '0px 0px 6px green',
        });
      }
    });
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda