Click to See Complete Forum and Search --> : 2 onSubmit... Same Form
adalby
02-06-2006, 03:38 PM
I've got 2 different javascripts and they both call for a form onsubmit. Is it possible to combine the 2 in the same form somehow? They are:
onSubmit="return checkFields();"
onsubmit="return validate(this)"
<form ACTION="/cgi/test.asp" METHOD="POST" name="form1">
Thanks,
Aaron
Selrach
02-06-2006, 03:48 PM
sure
function supersubmit(tag){
return (checkFields() || validate(tag));
}
<form action="/cgi/test.asp" method="post" name="form1" onsubmit="return supersubmit(this);">
adalby
02-06-2006, 04:08 PM
The first onsubmit worked and validated to see if the 2 fields were filled in and gave me an alert. When I clicked on "OK" it sent me to the 2nd onsubmits page. This may not be compatable for both scripts together but If you want to see my page code here it is.
<html>
<head>
<title></title>
<script languange = "javascript">
var phase=false;
function validate(myForm) {
if (!phase) {
document.getElementById("phase1").style.display="none";
document.getElementById("phase2").style.display="block";
document.getElementById("recall").innerHTML=document.forms.form1.text_box.value;
document.getElementById("recall1").innerHTML=document.forms.form1.text_box1.value;
phase=true;
return false;
}
else {
return true;
}
}
function revert(){
phase=false;
document.getElementById("phase1").style.display="block";
document.getElementById("phase2").style.display="none";
}
</script>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function checkFields() {
missinginfo = "";
if (document.form1.text_box.value == "") {
missinginfo += "\n - First Name";
}
if (document.form1.text_box1.value == "") {
missinginfo += "\n - Last Name";
}
if (missinginfo != "") {
missinginfo ="_____________________________\n" +
"You failed to correctly fill in your:\n" +
missinginfo + "\n_____________________________" +
"\nPlease re-enter and submit again!";
alert(missinginfo);
return false;
}
else return true;
}
// End -->
</script>
<SCRIPT LANGUAGE="JavaScript">
function supersubmit(tag){
return (checkFields() || validate(this));
}
</script>
</head>
<body>
<form action="/cgi/test.asp" method="post" name="form1" onsubmit="return supersubmit(this);">
<div id="phase1">
<p>Text Box <input type="text" name="text_box" size="20"></p>
<p>Text Box1 <input type="text" name="text_box1" size="20"></p>
<p><input type="submit" value="Submit">
<input type="reset" value="Reset"></p>
</div>
<div id="phase2" style="display:none;">
<P>You wrote: <span id="recall"></span></P>
<P>You wrote1: <span id="recall1"></span></P>
<P><input type="submit" value="Yes this is correct."> <input type="button" value="No go back"
onclick="revert()"></P>
</div>
</div>
</form>
</body>
</html>