alert message on submit

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
myasirm
Forum Commoner
Posts: 54
Joined: Sat Sep 12, 2009 3:57 am

alert message on submit

Post by myasirm »

hi guys i want to put a alert message on submit button when i click on that it ask that "Are you sure you want to submit" if i click yes the form should submit if no that it do no thing

kindly help me in this regards waiting for your replies
cokeetang
Forum Newbie
Posts: 3
Joined: Mon Oct 12, 2009 1:24 pm

Re: alert message on submit

Post by cokeetang »

document.getElementById("form").onsubmit=function(){
if(!confirm("Are you sure you want to submit?"))
return false;
return true;
}
User avatar
dheeraj
Forum Commoner
Posts: 40
Joined: Fri Feb 06, 2009 11:54 am

Re: alert message on submit

Post by dheeraj »

you have to use js, do following stuff to get your answer::

call a function in submit button like:::

Code: Select all

<input type="submit" name"Submit" Value="Submit" onclick="return form_action()">
after that write below js code in head section::

Code: Select all

 
<script type="text/javascript">
function form_action()
{
if(alert("You really want to submit form"))
   return true;
else
   return false;
}
</script>
 
that sit
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: alert message on submit

Post by Mirge »

dheeraj wrote:you have to use js, do following stuff to get your answer::

call a function in submit button like:::

Code: Select all

<input type="submit" name"Submit" Value="Submit" onclick="return form_action()">
after that write below js code in head section::

Code: Select all

 
<script type="text/javascript">
function form_action()
{
if(alert("You really want to submit form"))
   return true;
else
   return false;
}
</script>
 
that sit
An alert() does not give you any options. It's not for giving the user an option. And I wouldn't use an onclick handler for the submit button, I'd use instead the "onsubmit" event for the form itself.

For example:

Code: Select all

 
<html>
<head>
<title>Test</title>
<script type="text/javascript">
function ConfirmSubmit()
{
    return confirm("Are you sure you want to submit this form?"); // could convert to if/else
}
</script>
</head>
<body>
<form action="handler.php" method="post" onsubmit="return ConfirmSubmit();">
    Name: <input type="text" name="name" /><br />
    Age: <input type="text" name="age" /><br />
    <input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
 
Just threw it together here, untested. But that is the method I'd use.
myasirm
Forum Commoner
Posts: 54
Joined: Sat Sep 12, 2009 3:57 am

Re: alert message on submit

Post by myasirm »

thanks to all of u i have done this with your help
thanks
Post Reply