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.
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.
Share Improve this question asked May 16, 2011 at 23:49 IncognitoIncognito 1,9535 gold badges21 silver badges28 bronze badges 2 |3 Answers
Reset to default 9You 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:
- jQuery UI (dialog)
- jQuery Tools - Overlay
Could be more adequate ones out there. Been a while using such stuff
You can't do this from an "alert" box if thats what you mean.. But you could use any number of libraries to create a popup window which is basically just a and do your form within there.
You could then tie a button or whatever to a function which closes the box and parses the form into your structures within Javascript.
prompt()
call. Of course there are other ways to mimic this. – Jason Commented May 17, 2011 at 0:06