+1 Aayush Patidar · February 7, 2016
Can I take input from user in the JavaScript ?

Post a Reply


Oldest  Newest  Rating
0 Linguist Llama · February 8, 2016
@Ranic from reading through your posts I can see you probably know this, but you can use JS as a server-side language.
0 Danil Sorokin · February 8, 2016
At least, there's one way to get data from user: using html tag <input>. You can read the data from input by jQuery with
$(<select your input here>).val(); 

Another way is:

print("Type some text and press <ENTER>:\t");
var userInput = readline();
print("User input: " + userInput);

but it works only with spidermonkey and is not a part of js.
Hoping, that was helpful
0 Miss Protocol · February 8, 2016
if you want to get the keyboard input, from a user do this
<input type="text" id="getinput"/>
  var text = document.querySelector("#getinput");
text.onkeyup = function(e){
// alert("you pressed" + e.keyCode);
console.log("You pressed" + e.keyCode);
  • 1



A scripting language that is added to standard HTML to create interactive effects, apps, games for the browser.