0

Does Javascript have something similar to the alert builder in Java, I want to have a button that when clicked displays an alert with a set of options and when the option is clicked it triggers a callback with passing the selected option?

Or am I going to be looking at putting some sort of Java call in my code to pass the response back?

Lawtonj94
  • 309
  • 1
  • 5
  • 16

3 Answers3

0

If you want a simple confirm dialog you can do something like this:

JavaScript

if(confirm("Should I do it?")) 
{ 
   console.log("Go for it");
}

Otherwise you should probably look at something like jQueryUI to make modal dialogs.

Arg0n
  • 8,283
  • 2
  • 21
  • 38
0

You can check http://bootboxjs.com/ that does prompting with callbacks.

Unless its a simple confirm with a yes or not, you will have to use a library\write your own plugin.

Dima Grossman
  • 2,800
  • 2
  • 21
  • 26
0

this jsfiddle is what you're after, by StriplingWarrior. Basically it requires jquery UI dialog plugin, and like that you can have multiple inputs and handle input events right there on declaration

buttons: {
   "Yes": function() {
      alert('you chose yes');
   },
   "No": function() {
      alert('you chose no');
   },
   "Cancel": function() {
      dialog.dialog('close');
   }
}

A similar question was asked here: stackoverflow

Community
  • 1
  • 1
Joe Borg
  • 65
  • 2
  • 12