I am not able to store the input in the variables after submitting my form. It shows "undefined" Here's the code:
var userInput1 = document.getElementById("inp1").value;
var userInput2 = document.getElementById("inp2").value;
var userInput3 = document.getElementById("inp3").value;
function king() {
document.write("Welcome " + userInput1)
return false;
}```
Check this example. It's fun to use JQuery too for shorter Syntaxes. (My example is pure JS)
function fetch(){
var name = document.getElementById("name").value;
var age = document.getElementById("age").value;
//display
document.getElementById("demo").innerHTML = 'Welcome "' + name + '" Your age is: "'+ age +'"';
}
<!DOCTYPE html>
<html>
<body>
<fieldset>
<legend>Sample</legend>
<label>Name:</label>
<input type="text" id="name"/>
<br><br>
<label>Age:</label>
<input type="number" id="age"/>
<br><br>
<button onclick="fetch()">Fetch Data</button>
</fieldset>
<p id="demo"></p>
</body>
</html>