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

80
Views
JavaScript/html show alert which includes label input

I'm using HTML5 and JavaScript

I want to be able to input any word into a label and when you click on the button it gives an alert which includes the given text.

I cannot get it to work with the text I put into the label the alert shows no text. I've only found how to do it with predefined labels.

Here's my current html code

function getinput() {
  var input = document.getElementById("form-scream").innerText;
  alert(input);
};
<div>
  <p>Word
    <label id="form-scream"></label>

    <input type="text" name="screaming" id="form-scream">

    <button onclick="getinput()"> Click to scream</button>
  </p>
  <script src="assets/js/scream.js"></script>
</div>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

input element does not have innerText property, use value instead. Also, you have use for attribute in a label to associate an element (the element's id as the value of for):

function getinput()
{
  var inputVal = document.getElementById("form-scream").value;
  alert(inputVal);
};
<div>
    <p>Word
    <label for="form-scream"></label>

    <input type="text" name="screaming" id="form-scream">

    <button onclick="getinput()"> Click to scream</button>
    </p>
    <script src="assets/js/scream.js"></script>
</div>

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!