View Full Version : can we have 2 onsubmit in a <form>?
ClueLess
03-06-2003, 08:15 PM
Is it possible to have 2 onsubmit(s) in a FORM????
I've tried something like this, but it's not working.
<form action="test.asp" name="MainForm" method="post" onsubmit="validate()" onsubmit="EnterDate()">
Thanks.
Quiet Storm
03-06-2003, 10:26 PM
Yes, it is possible:
onsubmit="validate(); EnterDate();"
cheesebagpipe
03-06-2003, 10:30 PM
That won't cut it if validate() returns true or false for submission purposes (typical scenario). What's in those functions?
ClueLess
03-07-2003, 02:58 PM
Before it calls to 2nd onSubmit which is, EnterDate(); . I have a validate function.
If the user won't enter a First Name field, but they click Submit button, then the alert message will pop-up saying that "Frist Name is required".
Right now, if they click OK from a pop-up alert message, the Prompt Enter Date shows/also pop-up. I don't want the "Prompt Enter Date" shows/pop-up when the use clicks OK from the Alert Message.
Can we hide the Prompt Enter Date when the use click OK from the Validate Alert Message.
However, the use has to enter the date when they submit the form, this is required.
Thanks for your help
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<script language="javascript">
function validate() {
var form = document.forms[0];
if (form.firstname.value == "") {
alert("Frist Name is required");
return false;
}
}
</script>
<body>
<form name="formcheck" onsubmit="validate(); EnterDate();">
First Name: <input type=text name="firstname" size="25"><br>
Last Name: <input type=text name="LastName" size="25"><br>
<input type=submit value="Submit">
</form>
</body>
</html>
Roy Sinclair
03-07-2003, 10:25 PM
Do it this way:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<script language="javascript">
function validate() {
var form = document.forms[0];
if (form.firstname.value == "") {
alert("First Name is required");
return false;
}
return EnterDate();
}
</script>
<body>
<form name="formcheck" onsubmit="return validate();">
First Name: <input type=text name="firstname" size="25"><br>
Last Name: <input type=text name="LastName" size="25"><br>
<input type=submit value="Submit">
</form>
</body>
</html>
Note that for event handlers like this you should always use the "return yourfunctionname();" form. When you fail to do that some browsers don't work correctly. Also all your functions called by an event handler should always return a true or false value, you shouldn't count on a default value.
Lastly, if you do have a situation where you can't call one function from another like the changes I suggested above and yet you need to make sure the event is canceled if either function fails then use "return function1() && function2()" . The && causes a "logical and" to be done with the results of both functions only if both functions return true will a value of true be returned to the event handler causing the event to proceed. If either or both functions return false then a value of false will be returned to the event handler and the event will be canceled.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.