0

I need the user to choose either choice on the decision box before they go for next page. Right now the problem is if the user click close "X" on popup box, they can proceed for next page without choosing the choice. How can i do validate from here? Any help would be appreciated. Thanks

enter image description here

Javascript Code

var winConfirm = null;

function showConfirm() {
    var windowWidth = 250;
    var windowHeight = 100;
    var locX = (screen.width - 150 - windowWidth) / 2;
    var locY = (screen.height - 50 - windowHeight) / 2;
    var windowFeatures = "width=" + windowWidth + ",height=" + windowHeight + ",screenX=" + locX + ",screenY=" + locY + ",left=" + locX + ",top=" + locY;


    if ((winConfirm != null) && !winConfirm.closed) {
        winConfirm.close();
    }


    winConfirm = open("menubar = no", "winConfirm", windowFeatures);

    var theHTML = '' + '<BODY BGCOLOR="#DDDDDD">' + 
   '<CENTER><B><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="#FF0000">' + 'Please choose ?' + '</B></CENTER><FORM NAME="buttonForm"><BR/>
     <TABLE BORDER="0" WIDTH="100%" CELLPADDING="0" CELLSPACING="0">
     <TR>
     <TD width="40" ALIGN="CENTER"> &nbsp;</TD>
     <TD>' + '<INPUT TYPE="button" NAME="buttonname" VALUE="YES" STYLE="WIDTH:60;HEIGHT:30;FONT-WEIGHT:BOLD;" ONCLICK="self.close();opener.buttonClicked(0);">' + '&nbsp;' + '</TD>
     <TD ALIGN="CENTER"><INPUT TYPE="button"  NAME="buttonname" VALUE="NO" STYLE="WIDTH:60;HEIGHT:30;FONT-WEIGHT:BOLD;"  ONCLICK="self.close();opener.buttonClicked(1);">' + '</TD>
     <TD WIDTH="40"> &nbsp; </TD>
     </TR></TABLE></FORM></BODY>';

    winConfirm.document.writeln(theHTML);
}


function buttonClicked(buttonChoice) {
    var CONTACT_ID = "<%=CONTACT_ID%>";

    switch (buttonChoice) {
        case 0:
            winConfirm.close();
            break;
        case 1:
            popupWindow('/eascb/common/search/pop_contact_update_0.jsp');
            break;
        default:
            popupWindow('pop_covernote_add_0.jsp');
    }
}
user3835327
  • 1,194
  • 1
  • 14
  • 44

3 Answers3

0

You can't remove the window options, BUT you can create your own pop up box in your page using JavaScript. Just have Javascript generate a DOM with two clickable buttons. Besides, that way you have complete control over the aesthetic as well. I'm on mobile right now, but I'll write you an example tomorrow morning if no one else beats me to it.

EDIT - Adding example

Instead of having javascript generate them I just used html and css classes, but it should still display what I was trying to get at. If you don't have access to the html or css I could help you write some javascript that does actually generate the DOM.

http://jsfiddle.net/fcpxrkh0/

<div id="clickMe" onClick="clickMe()">Click Me!</div>

<div id="modal" class="hideModal">
    <p>Please select Yes or No</p>
    <div id="buttonYes" class="button" onClick="selected(this.id)">YES</div>
    <div id="buttonNo" class="button" onClick="selected(this.id)">NO</div>
</div>

<script>

    function clickMe() {
        document.getElementById('modal').className = "";
    }


    function selected(clicked_id) {

        var selectedOpt = clicked_id; 

        if (selectedOpt == 'buttonYes') {
            alert('Yes Clicked');
        }

        else {
            alert('No Clicked');
        }

    }

</script>
Steely
  • 117
  • 7
  • Thanks @steely. I'll try the method that you had just mentioned while waiting for your solution. – user3835327 Oct 03 '14 at 03:40
  • There are about a thousand solutions to this problem (simulating a modal in the DOM): http://stackoverflow.com/questions/288867/how-to-code-a-javascript-modal-popup-to-replace-ajax , http://github.hubspot.com/vex/docs/welcome/ , http://bootboxjs.com/ , and so on. – caseygrun Oct 03 '14 at 03:48
  • Edited to add example. Hope it helps! – Steely Oct 03 '14 at 16:24
  • @user3835327 , did my answer help? Please select the best answer if you would. ;) – Steely Nov 19 '14 at 18:30
0

You can also use confirm to display a native modal popup window, where the user must choose OK or Cancel; How to create a dialog with “yes” and “no” options? .

Community
  • 1
  • 1
caseygrun
  • 2,019
  • 1
  • 15
  • 21
  • native modal popup window only return true or false, which the button shows only "OK" and "CANCEL" instead of "Yes/ No".hmm.. – user3835327 Oct 03 '14 at 03:42
0

check out the fiddle demo. all I did was add a simple flag to hold the status if a button has been clicked, you can modify to your problem accordingly.

the flag name is somethingChosen, it is set to true once button is clicked, else would stay false and keep requesting for window to open.

mido
  • 24,198
  • 15
  • 92
  • 117