How do I create a javascript prompt box where you have to select 1 of 3 choices? I'm looking to do something similar to a html form's radio buttons except within a javascript prompt.
Checkboxes and radio buttons are elements for making selections. Checkboxes allow the user to choose items from a fixed number of alternatives, while radio buttons allow the user to choose exactly one item from a list of several predefined alternatives.
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.
In JavaScript, we use the prompt() function to ask the user for input. As a parameter, we input the text we want to display to the user. Once the user presses “ok,” the input value is returned. We typically store user input in a variable so that we can use the information in our program.
You could use jQuery and do a 3 button dialog(). Check out this working jsFiddle demo:
$("#dialog").dialog({
autoOpen: true,
buttons: {
Yes: function() {
alert("Yes!");
$(this).dialog("close");
},
No: function() {
alert("No!");
$(this).dialog("close");
},
Maybe: function() {
alert("Maybe!");
$(this).dialog("close");
}
},
width: "400px"
});
This can't be achieved natively as .prompt()
. This functionality requires more advanced JS. Here are some libs to mess with:
Could be more adequate ones out there. Been a while using such stuff
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