Input length is undifined

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Input length is undifined



< Why Input Length Is Undifined



Js


function calc() {
var inp = document.getElementById("inp");
var result = document.getElementById("result");
var inpval = inp.value

result.innerHTML = inpval;
alert(inp.length);
}



Html


<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<input id="inp" class="inp" Type="number"/>
<center>
<div id="calc" class="calc" onclick="calc()">Calculate</div>
<br />
<br />
<p id="result"></p>
</center>
</body>
</html>



Please help me with this code I don't know why I am getting this error whenever I click on function it always shows undifined





inpval.length vs inp.length?
– D. Seah
3 mins ago





inp is a dom element so it doesnt have a length property.
– Yonggoo Noh
2 mins ago




inp


length





inp is a html element its not an array and hence does not have any length property thats whyy you are getting undefiend
– fayeed
2 mins ago









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

Visual Studio Code: How to configure includePath for better IntelliSense results