+ 1
Input In JS
How can I use something inputed on an HTML page in an if/switch statement?
2 Answers
+ 15
Example-
var myName = prompt("Enter Name");// stores whatever you put in the prompt to the myName variable.
if(myName==""){
document.write("Please Enter a valid name.");
}else{
document.write("Nice name " + myName);
}
//you just need to declare your myName variable to use whatever you inputed using the prompt method.
+ 7
HTML
<input id="myInput" />
JS
input = document.getElementById("myInput").value;
if(input === someValue){
// do something
}