Input length is undifined
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
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.
inpval.length vs inp.length?
– D. Seah
3 mins ago