HTML इनपुट वैल्यू एक स्ट्रिंग होती है। स्ट्रिंग को पूर्णांक में बदलने के लिए, parseInt() का उपयोग करें।
उदाहरण
निम्नलिखित कोड है:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<body>
<input type="text" id="txtInput" placeholder="Enter a number">
<button type="button" onclick="result();">GetANumber</button>
</body>
<script>
function result() {
var numberValue = document.getElementById("txtInput").value;
if (!isNaN(numberValue))
console.log("The value=" + parseInt(numberValue));
else
console.log("Please enter the integer value..");
}
</script>
</html>
उपरोक्त प्रोग्राम को चलाने के लिए, फ़ाइल का नाम "anyName.html(index.html)" सेव करें। फ़ाइल पर राइट-क्लिक करें और VS Code एडिटर में "Open with Live Server" विकल्प चुनें।
आउटपुट
यह कंसोल पर निम्नलिखिक आउटपुट देगा:

अब, टेक्स्ट बॉक्स में वैल्यू दर्ज करें।

अब बटन दबाएं, आपको निम्नलिखिक आउटपुट मिलेगा।
यह निम्नलिखिक आउटपुट देगा:

कंसोल में आउटपुट:
