I want to take multiple user inputs from user in a single prompt box. How can this be possible?
-
1It's not possible. `prompt` is not made for that. Unless you want users to put a separator in their answer and you can split for that. But it's ugly and error-prone. – Federico klez Culloca Jul 31 '19 at 09:47
-
You'd need either multiple prompts, or a single prompt with a separator that the user is forced to enter. Or you could make your own custom modal. – Jack Bashford Jul 31 '19 at 09:48
-
Use a `` with HTML instead. A little more work, but can be integrated with the design of the page a lot more than a prompt widget, controlled by the browser. – Tigger Jul 31 '19 at 09:48
-
Anyway, why use a prompt and not a form? – Federico klez Culloca Jul 31 '19 at 09:48
3 Answers
In not possible in native browser behavior.
You need use custom library for creating modal element. For example you can use jQuery UI

- 589
- 7
- 15
The only way to do it would be to have a common separator that you split on. For instance, for the delimiter ~
, you could do this:
const inputs = prompt("Enter your inputs separated by a tilde ~").split("~");
console.log(inputs);
This is not a good way to obtain multiple inputs due to the fact that the user may make a mistake when entering their data. A much better way would be to make your own custom modal with multiple areas to input data, or simply do use many sequential prompts. But no, aside from this method, there's no way to get multiple user inputs in a single, browser default prompt box.

- 43,180
- 11
- 50
- 79
It is only possible by asking user to provide multiple data with delimeters e.g. input1 input2 input1,input2
and you can describe the format in prompt box message.

- 481
- 2
- 11