Page 1 of 1
alert message on submit
Posted: Tue Oct 13, 2009 4:15 am
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
Re: alert message on submit
Posted: Tue Oct 13, 2009 4:29 am
by cokeetang
document.getElementById("form").onsubmit=function(){
if(!confirm("Are you sure you want to submit?"))
return false;
return true;
}
Re: alert message on submit
Posted: Tue Oct 13, 2009 4:32 am
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
Re: alert message on submit
Posted: Tue Oct 13, 2009 4:54 am
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.
Re: alert message on submit
Posted: Tue Oct 13, 2009 5:33 am
by myasirm
thanks to all of u i have done this with your help
thanks