How can I create an alert dialog with buttons other than OK and Cancel?

Jayesh Nazre

Well with the confirm method given by JavaScript you cannot but with IE4 and above you can use the showModalDialog method to make a confirm box of your own.

NOTE: the showModalDialog() will only work with IE browser, NS has no method to show a modal dialog box.

The following code will work in IE4 and above. Also note that the third argument to the function has a lot of other attributes. Some of these are not supported in IE4 version also. For a detailed list please refer the following URL: showModalDialog Method.

The code for the main HTML:

<html>
<head>
<script language=javascript>
function test() {
var retvalue;
retvalue = window.showModalDialog("modal.html","", 
    "dialogHeight=5;dialogWidth=10;center=1;status=0;resizable=0;help=0");
alert (retvalue);
}
</script>
</head>
<body>

<form name=frm_test id=frm_test>
<input type=button value=Click onclick=test()>
</form>

</body>
</html>
The code for the modal.html which will be called when u click the "Click" button.

<html>
<title>Confirm</title>
<head>
<script language=javascript>
function test1() {
	window.returnValue = true;
	self.close();
}

function test2() {
	window.returnValue = false;
	self.close();
}

</script>
</head>
<body bgcolor=silver>
Are u Sure?
<input type=button value=YES onclick=test1()> <input type=button value=NO onclick=test2()> </body> </html>
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact