Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show list of options using JavaScript prompt

In JavaScript, is it possible to show a list of options to click using a prompt window, instead of a list of options to be typed in manually?

I'd like to present each option as a button, instead of asking the user to type the options manually (as shown here):

var OptionChosen = prompt('Enter 1, 2, 3, or 4:')

like image 725
Anderson Green Avatar asked May 15 '13 02:05

Anderson Green


People also ask

How do you prompt in JavaScript?

The prompt() method displays a dialog box that prompts the user for input. The prompt() method returns the input value if the user clicks "OK", otherwise it returns null .

What does the JavaScript prompt () method do?

Javascript | Window prompt() Method. The prompt() method is used to display a dialog box with an optional message prompting the user to input some text. It is often used if the user wants to input a value before entering a page. It returns a string containing the text entered by the user, or null.

What is prompt box in JavaScript?

A prompt box is often used if you want the user to input a value before entering a page. When a prompt box pops up, the user will have to click either "OK" or "Cancel" to proceed after entering an input value. If the user clicks "OK" the box returns the input value.


1 Answers

You can't do that, but you could use jQuery dialog box instead.

Example jQuery:

var selected = 0;
$('#dialog').dialog({
  title: "Prompt",
  buttons: {
    "First": function() {
      selected = 1;
    },
    "Second": function() {
      selected = 2;
    },
    "Third": function() {
      selected = 3;
    },
    "Fourth": function() {
      selected = 4;
    }
    // ..............
  }
});

with html:

<div id="dialog">
    <p>Choose your option</p>
</div>
like image 185
PSR Avatar answered Sep 29 '22 09:09

PSR