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

139
Visualizações
Javascript counting the letters inputed in email instead of outputting the email itself

I'm stuck on trying to get the email outputted instead of numbers related to the amount of words inputed

var output2 = "Email: " + at; is counting the amount of letters that was inputed.

I'm trying to figure out how its counting the amount of letters and why is it not outputting the email instead

Demo in Stack Snippets

function myFunction() {
  var uname = document.getElementById("uname").value;
  var age = document.getElementById("age").value;
  var at = document.getElementById("email").value.indexOf("@");
  submitOk = "true";


  if (uname.length > 16) {
    alert("Characters have exceeded specified amount");
    submitOk = "false";
  }

  if (age < 13 || age > 19) {
    alert("Numbers must be between 13 and 19");
    submitOk = "false";
  }

  if (at == -1) {
    alert("not a valid E-mail");
  }

  if (submitOk == "false") {}

  if (submitOk == "true") {}

  var output = "Name: " + uname;
  var output1 = "Age: " + age;
  var output2 = "Email: " + at;

  document.getElementById("output").innerHTML = output;
  document.getElementById("output1").innerHTML = output1;
  document.getElementById("output2").innerHTML = output2;
}
<form onsubmit="return myFunction()">
  Name : <br><input type="text" id="uname" size="30" placeholder="Maximum of 16 Characters"><br> Age : <br><input type="number" id="age" size="30" placeholder="From 13 to 19 only"><br> E-mail : <br><input type="text" id="email" size="30" placeholder="Examplename@mail.com"><br>
  <br>
  <input type="submit" onclick="myFunction();return false" value="Submit">
</form>

<table class="center">
  <tr>
    <td>
      <div id="output"></div>
    </td>
  </tr>
  <tr>
    <td>
      <div id="output1"></div>
    </td>
  </tr>
  <tr>
    <td>
      <div id="output2"></div>
    </td>
  </tr>
</table>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It looks like at is being used to verify that the email has an @ symbol, not neccessarily return the pure value as seen here where it's calculated:

var at = document.getElementById("email").value.indexOf("@");

indexOf("@") will return the position of the first at symbol if found, or -1 if not found.

If you just want the email address, you can break into two statements:

var email = document.getElementById("email").value;
var at = email.indexOf("@");
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