Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!