0

I need to popup a window with three buttons when the user clicks on a text.

What I have in my java class:

myHtml.append("<a href=\"" + myUrl+ "\" onclick=\"javascript: return confirm('" + myMessage + "')\">" + myLink + "</a>");

What I need is to not use "confirm". I need to use a popup similar to confirm() but with 3 different actions.

How can I replace confirm() to have 3 different actions instead of "ok" and "cancel" only?

EDIT

I have another idea, I can call prompt from the java class but my problem is how to get the prompt result inside my java class??

myHtml.append("<a href=\"" + myUrl + "\" onclick=\"javascript: return prompt('" + myMessage + "')\">" + myLink + "</a>");
Roman C
  • 49,761
  • 33
  • 66
  • 176
twirey
  • 11
  • 1
  • 4
  • 1
    Use jquery ui dialog or some other custom plugins. – rrk Jun 01 '16 at 13:14
  • Why is this tagged with “java”? JavaScript and Java are completely different things. – VGR Jun 01 '16 at 13:49
  • 1
    @VGR Because Struts is Java, I assume, and the framework may include relevant functionality. (As it doesn't differentiate between Struts 1 and Struts 2, however, it's hard to say.) – Dave Newton Jun 01 '16 at 14:16
  • I can't add jquery to my project, im not using it at all. Please can you help me after I edited my question – twirey Jun 01 '16 at 17:39
  • Possible duplicate of [JavaScript alert with 3 buttons](http://stackoverflow.com/questions/2054082/javascript-alert-with-3-buttons) – Pascal Jun 02 '16 at 13:38
  • What are you doing is just rendering escaped html with a javascript, Struts in reality using some templates do do it in Java. – Roman C Jun 03 '16 at 16:35

2 Answers2

1

I don't think an alert pop-up with three buttons would be possible without using JQuery or some other custom dialog box. (As already pointed out in this question)

Since you're calling the prompt() function as part of your html document, I don't see a possibility to return the result to your java program as well. You could, however, expand your function attached to the onclick attribute in order to send it to your java program, even if I don't think this would be an elegant solution.

Community
  • 1
  • 1
aquilinux
  • 11
  • 4
0

You need to write an script for that customized pop-up window with three buttons. Try this once.

<script>
  $(function() {
    $( "#dialog-confirm" ).dialog({
      resizable: false,
      height:100,
      modal: true,
      buttons: {
        "Button 1": function() {
          $(this).dialog( "<something>");
        },
        "Button 2": function() {
          $(this).dialog( "<something>");
        },
        Cancel: function() {
          $(this).dialog( "close" );
        }
      }
    });
  });
  </script>
</head>

In the body tag of your html page. use following :

<div id="dialog-confirm" title="Empty the recycle bin?">
  <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>Your text here.</p>
</div>
Rish
  • 1,303
  • 9
  • 22