Skip to content

JavaScript prompt multiple input

  • by

JavaScript prompt multiple input is not possible in native browser behavior. You need to use a custom library for creating modal elements. For example, you can use jQuery UI.

Another way to do it would be to have a common separator that you split on. For instance, the delimiter ~, you could do this.

const inputs = prompt("Enter your inputs separated by a tilde ~").split("~");

console.log(inputs);

JavaScript prompts multiple input

Simple example code asking the user to provide multiple data with delimiters e.g. input1 input2 input1,input2

and you can describe the format in the prompt box message.

<!DOCTYPE html>
<html>
<body>

  <script>
    const inputs = prompt("Enter your inputs separated by a tilde ~").split("~");

    console.log(inputs);
  </script>

</body>
</html>

Output:

JavaScript prompt multiple input

Another example

<body>

<button onclick="myFunction()">Click me once</button>

<p id="demo"></p>

<script>
function myFunction() {
  let color = prompt("Please enter your favorite color here", "Black");
  if (color != null) {
    document.getElementById("demo").innerHTML =
    "WOW " + color + "! your choice is too good !!";
  }
}
</script>
</body>

Do comment if you have any doubts or suggestions on this Js input topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading