+ 1

Input In JS

How can I use something inputed on an HTML page in an if/switch statement?

18th Apr 2017, 8:34 PM
Christopher Carlson
Christopher Carlson - avatar
2 odpowiedzi
+ 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.
18th Apr 2017, 8:43 PM
ElricTheCoder
ElricTheCoder - avatar
+ 7
HTML <input id="myInput" /> JS input = document.getElementById("myInput").value; if(input === someValue){ // do something }
18th Apr 2017, 9:30 PM
Burey
Burey - avatar