Shrikant  Maurya
Shrikant Maurya

Reputation: 21

How to get multiple value in single prompt JavaScript?

How to get multiple values in single prompt JavaScript. Doesn't use the input form

var toText = prompt("From", "Lorem");
var fromText = prompt("To", "Ipsum");

Upvotes: 1

Views: 5656

Answers (3)

Yash Sonalia
Yash Sonalia

Reputation: 398

You can get multiple values by separating them with commas and using split method like this:


// Input: Hello, World, Lorem

const promptInput = prompt("Enter comma separated values");
const values = promptInput.split(",")
console.log(values)

// Output: ["Hello", "World", "Lorem"]

Upvotes: 1

Noa Yarin Levi
Noa Yarin Levi

Reputation: 191

window. prompt() instructs the browser to display a dialog with an optional message prompting the user to input some text, and to wait until the user either submits the text or cancels the dialog.- this is from mdn, you need input

Upvotes: 0

Dropout
Dropout

Reputation: 13866

You can get only one input using prompt. You will either have to display multiple prompts or implement a custom dialog window which will basically be a form.

Upvotes: 0

Related Questions