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 rotate image canvas 
Javascript :: js today timestamp 
Javascript :: js check tab active 
Javascript :: falsy javascript 
Javascript :: new create react app 
Javascript :: jquery keep scroll position 
Javascript :: javascript for...of index 
Javascript :: split text and join in js 
Javascript :: string interpolation javascript 
Javascript :: javascript if field exists 
Javascript :: jquery toggle show hide 
Javascript :: vue js required props 
Javascript :: javascript display 2 number after comma 
Javascript :: react js materilize 
Javascript :: jquery validation phone number 
Javascript :: javascript replace all occurrences of string 
Javascript :: finding by sub property of an object in mongo 
Javascript :: chart js stacked bar group 
Javascript :: vue computed composition api 
Javascript :: js json to object 
Javascript :: javascript validate date 
Javascript :: if jsp 
Javascript :: jquery form validation plugin callback function 
Javascript :: remove attribute onclick jquery 
Javascript :: how to make option selected edit in jquery 
Javascript :: change property name of object in array javascript 
Javascript :: find smallest number in array js 
Javascript :: video in react native stack overflow 
Javascript :: how to validate a string using regular expression in javascript 
Javascript :: pagination in strapi 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =