Reputation: 75
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<script type="text/javascript" src="fuctions.js"></script>
<title>Count JS</title>
</head>
<body>
<fieldset>
<input type="number" value="1" id="num" min="1" max="5"/>
<button onclick="getValue()">
Submit
</button>
</fieldset>
</body>
</html>
JS:
function getValue() {
var x = parseInt(document.getElementById("num"));
alert(x);
}
I just want to print this value that I get using document.getElementById
, but when I print appears it:
Can someone help?
Upvotes: 0
Views: 3012
Reputation: 77482
.value
returns value from input, in your case, you try convert DOMNode
to Integer
that will return NaN
var x = parseInt(document.getElementById("num").value);
Upvotes: 2
Reputation: 3397
Add .value
after document.getElementById
function getValue() {
var x = parseInt(document.getElementById("num").value);
alert(x);
}
Upvotes: 1