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

126
Views
Data value not stored in variables (showing undefined)

I am not able to store the input in the variables after submitting my form. It shows "undefined" Here's the code:

var userInput1 = document.getElementById("inp1").value;
  var userInput2 = document.getElementById("inp2").value;
 var userInput3 = document.getElementById("inp3").value;
function king() {
document.write("Welcome " + userInput1)
return false;
}```
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Check this example. It's fun to use JQuery too for shorter Syntaxes. (My example is pure JS)

function fetch(){
  var name = document.getElementById("name").value;
  var age = document.getElementById("age").value;
  
  //display
  document.getElementById("demo").innerHTML = 'Welcome "' + name + '" Your age is: "'+ age +'"';
}
<!DOCTYPE html>
<html>
<body>
<fieldset>
<legend>Sample</legend>
  <label>Name:</label>
  <input type="text" id="name"/>
  <br><br>
    <label>Age:</label>
  <input type="number" id="age"/>
  <br><br>
  <button onclick="fetch()">Fetch Data</button>
</fieldset>
<p id="demo"></p>
</body>
</html>

about 4 years ago · Santiago Gelvez 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!