0

Possible Duplicate:
Javascript Confirm popup Yes, No button instead of OK and Cancel

Please someone help me to make a confirm box with button "Yes" and "No" without using jquery or VB.Script. I have searched a lot but I got all of the answers with jquery but that is not my requirement.

I have to call another function from confirmbox function. The code I am using below

HTML

<a href="#" onlick="show_confirm('<?php echo $cat_id; ?>')">Delete</a>

And Javascript

<script type="text/javascript">
function show_confirm(cat_id)
{
  var conf = confirm("Are you sure you want to delete the file");
  if (conf ==true)
  {
    deleteCatagory(cat_id);
  }
}

function deleteCatagory(cat_id)
{
  var obj = document.getElementById("file_"+cat_id);
  callAjax(cat_id,obj);
}
</script>
Community
  • 1
  • 1
Jhilom
  • 1,028
  • 2
  • 15
  • 33

3 Answers3

2

Very simple. You'll have to custom code an HTML box that has a Yes and No button. The Yes button executes the code and hides the box, the No button just hides the box. Something as simple as this would do:

HTML

<div id="confirmation">
Are you sure you want to delete the category?<br>
<input type="button" onclick="deleteCategory(document.getElementById('catID').value);this.parentNode.style.display='none';" value="Yes">
<input type="button" onclick="this.parentNode.style.display='none';" value="No">
<input type="hidden" id="catID" value="0">
</div>

CSS

<style type="text/css">
<!--
#confirmation {
display: none;
position: absolute;
top: 50%;
left: 50%;
background-color: white;
border: 2px solid white;
padding: 3px;
text-align: center;
width: 200px;
height: 50px;
}
</style>

Updated show_confirm():

function show_confirm(catID) {
    document.getElementById('catID').value=catID;
    document.getElementById('confirmation').style.display='block';
}
Ashley Strout
  • 6,107
  • 5
  • 25
  • 45
0

You need to create it yourself, this: http://dev.sencha.com/deploy/ext-4.0.0/examples/message-box/msg-box.html seems to have a way to do it but this is from 5 minutes of googling. Others suggest using a div to do it, which is my personal preference.

Greg Flynn
  • 1,694
  • 2
  • 14
  • 15
-1

If you're fine with the "Ok" or "Cancel" options the confirm box gives you, you only need to fix the typo in your call. I'd do it like this

<a href="JavaScript:void(0);" onclick="show_confirm('<?php echo $cat_id; ?>');">Delete</a>​

If you however want to change the default text then you're out of luck with the default confirm popup. You'll have to come up with a html based "popup".

Koen Peters
  • 12,798
  • 6
  • 36
  • 59