ashleypower
10-27-2003, 06:48 PM
I have a form in which all fields must be complete. I've written a simple code that determines whether or not all fields have been completed. If all the fields are completed, then you are sent to a new page.
The button will let you know if you have an empty field, but even if there are empty fields, it sends you to the next page. For now, i've made the validation script and the script that sends you to the next page separate buttons. I'd like this all to be taken care of with one button click.
Is there any way that I can put both of these scripts on one submit button?
Here's my code:
============================================
<SCRIPT LANGUAGE="JavaScript">
<!--
function go() {
window.location='frame.htm';
}
function checkit() {
if(document.soac.FirstName.value =="") {
alert("Please enter first name");
return false;
}
if(document.soac.LastName.value =="") {
alert("Please enter last name");
return false;
}
if(document.soac.MailAddress.value =="") {
alert("Please enter your address");
return false;
}
if(document.soac.email.value.indexOf("@") == -1 || document.soac.email.value == "") {
alert("Please enter email address.");
document.soac.email.focus();
return false;
}
if(document.soac.email.value != document.soac.emailconfirm.value) {
alert("Confirm E-mail address.");
return false;
}
if(document.soac.PhoneNumber.value =="") {
alert("Please enter your phone number");
return false;
}
if(document.soac.HighschoolAttend.value =="") {
alert("Please enter your Highschool");
return false;
}
if(document.soac.FatherOccupation.value =="") {
alert("Please enter your Father's Occupation");
return false;
}
if(document.soac.MotherOccupation.value =="") {
alert("Please enter your Mother's Occupation");
return false;
} else {
alert("COMPLETE!");
}
}
function checkCR(evt) {
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}
document.onkeypress = checkCR;
//-->
</SCRIPT>
===========================================
Any help appreciated. Please keep in mind that I am kinda new to JavaScripting...Thanks.
The button will let you know if you have an empty field, but even if there are empty fields, it sends you to the next page. For now, i've made the validation script and the script that sends you to the next page separate buttons. I'd like this all to be taken care of with one button click.
Is there any way that I can put both of these scripts on one submit button?
Here's my code:
============================================
<SCRIPT LANGUAGE="JavaScript">
<!--
function go() {
window.location='frame.htm';
}
function checkit() {
if(document.soac.FirstName.value =="") {
alert("Please enter first name");
return false;
}
if(document.soac.LastName.value =="") {
alert("Please enter last name");
return false;
}
if(document.soac.MailAddress.value =="") {
alert("Please enter your address");
return false;
}
if(document.soac.email.value.indexOf("@") == -1 || document.soac.email.value == "") {
alert("Please enter email address.");
document.soac.email.focus();
return false;
}
if(document.soac.email.value != document.soac.emailconfirm.value) {
alert("Confirm E-mail address.");
return false;
}
if(document.soac.PhoneNumber.value =="") {
alert("Please enter your phone number");
return false;
}
if(document.soac.HighschoolAttend.value =="") {
alert("Please enter your Highschool");
return false;
}
if(document.soac.FatherOccupation.value =="") {
alert("Please enter your Father's Occupation");
return false;
}
if(document.soac.MotherOccupation.value =="") {
alert("Please enter your Mother's Occupation");
return false;
} else {
alert("COMPLETE!");
}
}
function checkCR(evt) {
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}
document.onkeypress = checkCR;
//-->
</SCRIPT>
===========================================
Any help appreciated. Please keep in mind that I am kinda new to JavaScripting...Thanks.