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:')
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 .
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.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With