1<!--
2This is example is with a number...
3But you can do it with whatever input type you want
4-->
5<input type="number" name="numberInput" id="numberInput" max="20" min="1" step="1">
6<button type="button" onclick="myFunction()">sumbit</button>
7
8<script>
9 function myFunction() {
10 let tokenAmount = document.getElementById("numberInput").value;
11 return // whatever you want to do with it
12 }
13</script>
1<form action="/">
2 <label for="">Whatever you want</label>
3 <input type="text" id='form'>
4 <input type="submit" id="submit">
5</form>
6
7<script>
8 const btn = document.getElementById('form');
9
10 btn.addEventListener('click', (e) => {
11 e.preventDefault(); // disable the refresh on the page when submit
12 const value = document.getElementById('submit').value;
13
14 console.log(value);
15 });
16</script>
1<!DOCTYPE html>
2<html lang="en">
3<head>
4<meta charset="utf-8">
5<title>Get Text Input Field Value in JavaScript</title>
6</head>
7<body>
8 <input type="text" placeholder="Type something..." id="myInput">
9 <button type="button" onclick="getInputValue();">Get Value</button>
10
11 <script>
12 function getInputValue(){
13 // Selecting the input element and get its value
14 var inputVal = document.getElementById("myInput").value;
15
16 // Displaying the value
17 alert(inputVal);
18 }
19 </script>
20</body>
21</html>