confirm button

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gammaman
Forum Commoner
Posts: 45
Joined: Tue Feb 12, 2008 9:22 am

confirm button

Post by gammaman »

I have this button that when clicked executes an oracle statement that starts a new data page. How can I have a confirm button in javascript (I know php does not really do confirm buttons) that sends a value to my button to know weather or not to execute the oracle statement. I cannot put the php code that contains the execute inside the javascript because javascript is client side and the oracle will be ignored.
solid
Forum Commoner
Posts: 28
Joined: Wed Aug 12, 2009 11:56 am

Re: confirm button

Post by solid »

You add a function in the page HEAD like this:

Code: Select all

<script type="text/javascript">
function validateForm()
{
   var r=confirm("Are you sure?");
   if (r==true)
   {
      return true;
   }
   return false;
}
</script>
Then you add an onSubmit attribute to your form tag (note that the HTML char after javascript is a colon):

Code: Select all

<form id="myForm" name="myForm" action="/" method="POST" onsubmit="javascript:validateForm();">
Post Reply