Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to get user input in javascript

var name = window.prompt("What is your name");
document.write("Hello " + name);
Comment

js get input from user

var name = prompt("Please enter your name", "Harry Potter");
Comment

how to get user input in javascrip

//using npm module
/* 
npm install prompt-sync
# or
yarn add prompt-sync

*/

const prompt = require('prompt-sync')();

const input = prompt('What is your name? ');

console.log(`Oh, so your name is ${input}`);

//* or using readline

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});

rl.question('What is your name? ', function (answer) {
  console.log(`Oh, so your name is ${answer}`);
  console.log('Closing the interface');
  rl.close();
});

//* for brouser input

const input1 = prompt();

const input2 = prompt("What's your name?");
alert(`Your name is ${input}`);

const input3 = prompt('Please enter your age:');
alert(`You are ${input} years old`);
Comment

user input in js

var username = prompt("What is your name?");
Comment

how to get a user input in js

Copyvar name = window.prompt("Enter your name: ");
alert("Your name is " + name);
Comment

PREVIOUS NEXT
Code Example
Javascript :: what is JSON TREE 
Javascript :: how to add items in an array in js 
Javascript :: how to unselect input javascript 
Javascript :: set input value vanilla js 
Javascript :: Iteration over JS object 
Javascript :: javascript dump strack trace 
Javascript :: first letter uppercase js 
Javascript :: at in js 
Javascript :: react webpack config example 
Javascript :: how to make a random if else in js 
Javascript :: javascript compare two arrays of objects 
Javascript :: debug react routes 
Javascript :: javascript sum of arguments 
Javascript :: how to convert seaconds into hh:mm:ss in javascript 
Javascript :: Number of documents in Mongodb 
Javascript :: JS toString adds backslash 
Javascript :: Find the stray number 
Javascript :: json load 
Javascript :: xmlhttprequest js 
Javascript :: send csrf token ajax laravel 
Javascript :: npm run build serve 
Javascript :: vue router guard 
Javascript :: react prevent form submission on enter key press inside inputs 
Javascript :: react context 
Javascript :: merge sort javascript 
Javascript :: java script login system 
Javascript :: convert a string to an array javascript 
Javascript :: how to remove property of object in javascript without delete 
Javascript :: angular new component 
Javascript :: reg ex with filter in js 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =