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

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 :: array sort numbers 
Javascript :: angular9 spy 
Javascript :: vanilla js append new element 
Javascript :: javascript integer to binary 
Javascript :: d3 v6 
Javascript :: how to use mui 
Javascript :: indefOf 
Javascript :: form contact 7 ajax send 
Javascript :: js element on mouse over 
Javascript :: concat js 
Javascript :: headless ui modal 
Javascript :: react input radio button 
Javascript :: next js link 
Javascript :: redirect to dashboard after login in vue 
Javascript :: How can i change Header Bar height in react native 
Javascript :: query parameters 
Javascript :: how to validate password and confirm password on react form hook 
Javascript :: nodejs request post 
Javascript :: state in react 
Javascript :: node http2 post 
Javascript :: multi key cookie js 
Javascript :: rngesturehandlermodule.default.direction react native 
Javascript :: Add jquery in extension 
Javascript :: fsm2regex 
Javascript :: monaco editor no numbers 
Javascript :: react carousel 
Javascript :: disable textbox on plumsail 
Javascript :: require cycle disable warning react native 
Javascript :: expo av 
Javascript :: react update version 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =