Nipun Gujarathi
Nipun Gujarathi

Reputation: 1

How to show popupalert using javascript in my jsp page?

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.

Upvotes: 0

Views: 1313

Answers (3)

Abinash Sinha
Abinash Sinha

Reputation: 840

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...
}

Upvotes: 3

Jayesh
Jayesh

Reputation: 6111

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/

Upvotes: 0

Coder
Coder

Reputation: 7076

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

Upvotes: 0

Related Questions