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

Accessing user input through js

var x = document.getElementById("myText").value;
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript find factorial 
Javascript :: express cookieparser 
Javascript :: math from string js 
Javascript :: discord bot remove message reaction 
Javascript :: react native material bottom tabs 
Javascript :: copia array javascript 
Javascript :: how to add toggle class in javascript using css modules 
Javascript :: shuffle array 
Javascript :: react file preview 
Javascript :: date range npm 
Javascript :: threejs perspectivecamera 
Javascript :: array sort numbers 
Javascript :: angularjs make post request 
Javascript :: prepend to js array 
Javascript :: next js get gurrent page params 
Javascript :: javascript string spaces replace with %20 
Javascript :: how to slice array in angular 6 
Javascript :: next js link 
Javascript :: access to nested properties on javascript using property names 
Javascript :: prisma bigint 
Javascript :: sequelize association alias 
Javascript :: check if an input element has focus 
Javascript :: how to update state.item[1] in state using setState? React 
Javascript :: uncaught exception javascript 
Javascript :: floor html 
Javascript :: what is closure in javascript 
Javascript :: json type error at login 
Javascript :: monaco editor no numbers 
Javascript :: enzyme test method 
Javascript :: how to disable security in jhipster 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =