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

138
Vistas
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 Respuestas
Responde la pregunta

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 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