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)" को सेव करें। फ़ाइल पर राइट क्लिक करें और वीएस कोड संपादक में "लाइव सर्वर के साथ खोलें" विकल्प चुनें।
आउटपुट
यह कंसोल पर निम्न आउटपुट उत्पन्न करेगा -

अब, टेक्स्ट बॉक्स में एक मान दर्ज करें।

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

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