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

108
Visualizações
Is there a way to detect if a user has not answered an input?

I am making a name picker and I want to detect if your user has input a name or if they are just messing with the website. Is there a way to do this? Code:

<html>
<textarea id="names"></textarea>
<input type="submit" value="Pick" onclick="onClick(this)">
<p id="chosen"></p>
</html>
<script>
function onClick(x) {
//Your code
}
</script>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

The getNames() method is called for the <input> element to check for value when it submits, and a value is returned after the value inside the <textarea> element is checked.

/* This helper method checks whether the login has been made or not. */
function isNameEmpty(){
   var name = document.getElementById("names");
   
   if(name.value.length != 0){
      console.log(name.value);
      return false;
   }
   else{
      console.log('No value was entered.');
      return true;
   }
}

/* This submit method is used to return the entered name. */
function getNames(){
  if(!isNameEmpty()){
    return document.getElementById("names").value;
  }
  else{
    alert('No value was entered.');
    return '';
  }
}
<textarea id="names"></textarea>
<input type="submit" value="Pick" onclick="return getNames();">
<p id="chosen"></p>


References
  • Add onclick function to a submit button
about 4 years ago · Juan Pablo Isaza Relatório

0

you can change the textarea to input tag and you can use browser built in attributes like type= text min max length etc.

otherwise you should write a function that reads and evaluates the input value of the textarea

about 4 years ago · Juan Pablo Isaza Relatório
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