0

I have used confirm("") popup alert function of javascript in my jsp page and it shows 'OK' and 'Cancel' button but i want 'YES' and 'NO' instead.

Please tell me is there any way to do it or there is any alternative for it.

Trikaldarshiii
  • 11,174
  • 16
  • 67
  • 95
  • You might need to look http://stackoverflow.com/questions/823790/javascript-confirm-popup-yes-no-button-instead-of-ok-and-cancel – Coder Jul 25 '13 at 10:54

3 Answers3

3

If you are using confirm statement in javascript you cant change it. you will have to create a custom confirmation box using java script or jquery. Here is an optional method without using jquery or javascript

<style type="text/css">

div#popup
{
    position:absolute;
    display:none;
    top:200px;
    left:50%;
    width:500px; 
    margin-left:-250px;
    border:1px solid blue; 
    padding:20px;
    background-color:white;
}

</style>

<a 
    href="http://example.com/" 
    onClick="document.getElementById('popup').style.display = 'block'; return false;"
>Go to example.com</a>


<div id="popup">
    <p>Are you sure you want to go to example.com?</p>
    <p>
        <a onclick="document.location='http://example.com/'; return false;">
            Yes
        </a>
        <a onclick="document.getElementById('popup').style.display = 'none'; return false;">
            No
        </a>
    </p>
</div>

Also you can use jquery

function askUserYesOrNo() {
  var myDialog = $('<div class="mydialog"><p>Yes or No?</p><input type="button" id="yes" value="Yes"/><input type="button" id="no" value="No"/></div>');
  $("#yes").click(handleYes);
  $("#no").click(handleNo);
  myDialog.modal(); //This would have to be replaced by whatever syntax the modal framework uses
}

function handleYes() {
  //handle yes...
}

function handleNo() {
  //handle no...
}
Abinash Sinha
  • 840
  • 6
  • 18
0

javascript limits the option for customizing confirm box. So you cannot change the Confirm box buttons from OK/Cancel to YES/NO

You may use JQuery to customize that

Here is a link that uses JQuery and CSS3 for customized ConfirmBox

Coder
  • 6,948
  • 13
  • 56
  • 86
0

You can go for this Jquery base solution. It has option to add as many button you want and respective action to each.

http://stefangabos.ro/jquery/zebra-dialog/

Jayesh
  • 6,047
  • 13
  • 49
  • 81