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

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 :: livewire progress indicators javascript 
Javascript :: javascript string contains multiple substrings 
Javascript :: replace comma by new line in js 
Javascript :: how create an index mongodb 
Javascript :: assign an element value as key in array of objects 
Javascript :: get query params from url javascript 
Javascript :: materialize for react 
Javascript :: vue js select option disabled false 
Javascript :: javascript for loop on object 
Javascript :: javascript date get future 5minutes 
Javascript :: javascript innerwidth 
Javascript :: how to change tab color react bootstraps customixation 
Javascript :: how to get all form values in javascript 
Javascript :: does onclick work for textboxes javascript 
Javascript :: jquery select clear options 
Javascript :: nodejs wait function 
Javascript :: js string length 
Javascript :: react onclick function 
Javascript :: find lowest number in array js 
Javascript :: Error: Requires Babel "^7.0.0-0", but was loaded with "6.26.3". 
Javascript :: JS append content into a DOM element 
Javascript :: angular elementref 
Javascript :: adb bootloader reboot 
Javascript :: find smallest number in array js 
Javascript :: send event to child component angular 
Javascript :: jsconfig.json 
Javascript :: get css custom property javascript 
Javascript :: remove node module 
Javascript :: regExp numero français 
Javascript :: how to get innerhtml value in javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =