Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to display input value in javascript?

Im trying to display the value that i type in the input field in the class "summe" so after i type something in the input field it would say "Amount:50".What do i need to add for that to happen?

const btncalc = document.querySelector('.calcit');
const summetext = document.querySelector('.summe');

btncalc.addEventListener('click', function(){
    summetext.textContent = "Amount:";
});
<!DOCTYPE html>
<html lang="en">
  <body>
    Backendbenutzer: <input class='backenduser'></input><br>
    <span class='summe'>0.00</span><br>
    <button class='calcit'>Berechnen</button>
    <script src="./app.js"></script>
  </body>
</html>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You also need to read the value of that input so I used class selector (with [0] to indicate the first occurance) and appended it to the text:

const btncalc = document.querySelector('.calcit');
const summetext = document.querySelector('.summe');

btncalc.addEventListener('click', function(){
    var amount= document.getElementsByClassName("backenduser")[0].value;
    var mytext="Amount:" + amount ;
    summetext.textContent = mytext;
});
<!DOCTYPE html>
<html lang="en">
  <body>
    Backendbenutzer: <input class='backenduser'></input><br>
    <span class='summe'>0.00</span><br>
    <button class='calcit'>Berechnen</button>
    <script src="./app.js"></script>
  </body>
</html>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading