Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
176
rated 0 times [  178] [ 2]  / answers: 1 / hits: 17374  / 6 Years ago, mon, june 18, 2018, 12:00:00

so i am trying to make a simple calculator with 2 inputs then it concatenate them or divide ....



so first i want to check if the input value is in there



why won't this work ?
i am learning the basics of js so i don't want to use any library





console.log(document.getElementById('d1').value);

<html>

<head>
</head>

<body>
<input type=number id=d1>
</body>

</html>




More From » javascript

 Answers
13

By directly using console.log it’s logging the value when the page is loaded. As the input field is blank, it’s displaying nothing. Instead, you need an event handler that runs every time you add something to the input field. Check the below code.




document.getElementById(d1).addEventListener(input, () => console.log(document.getElementById(d1).value));

<input id=d1 type=number>




[#54181] Wednesday, June 13, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jenamackennac

Total Points: 304
Total Questions: 110
Total Answers: 107

Location: Ecuador
Member since Thu, Jun 4, 2020
4 Years ago
;