nikko50
04-23-2008, 02:08 PM
Hi all. Please help. I have a form with a validate onsubmit like this....
onsubmit="return validateTracking(this) && chkFormTrack(this)"
Why is the form trying to submit after validateTracking(this) is true. I thought the form only trys to submit after both are true?
Here is the javascript for the validatation......
<script>
function validateTracking(theForm){
if(theForm.track_num){
if((theForm.track_num.value == '') || (theForm.track_num.value == "Enter Tracking Number") || (theForm.track_num.value == "1z9r29a4")){
alert('Please enter a tracking number!');
theForm.track_num.style.backgroundColor='pink';
theForm.track_num.focus();
return false;
}}
if(theForm.shipper){
if (theForm.shipper.selectedIndex == 0)
{
alert("The first \"Shipper\" option is not a valid selection. Please choose one of the other options.");
theForm.shipper.style.backgroundColor='pink';
theForm.shipper.focus();
return (false);
}}
return (true);
}
function chkFormTrack(form) {
var isChecked=0;
for (i=0;i<form.elements.length;i++) {
var obj = form.elements[i];
if (obj.type == 'checkbox') {
if (obj.checked == true) { isChecked++; }
}
if (isChecked > 0) {
return true;
}
}
if (isChecked > 0) { return true;}
else { alert('Please choose item(s) to attach.');
return false;
}
}
</script>
onsubmit="return validateTracking(this) && chkFormTrack(this)"
Why is the form trying to submit after validateTracking(this) is true. I thought the form only trys to submit after both are true?
Here is the javascript for the validatation......
<script>
function validateTracking(theForm){
if(theForm.track_num){
if((theForm.track_num.value == '') || (theForm.track_num.value == "Enter Tracking Number") || (theForm.track_num.value == "1z9r29a4")){
alert('Please enter a tracking number!');
theForm.track_num.style.backgroundColor='pink';
theForm.track_num.focus();
return false;
}}
if(theForm.shipper){
if (theForm.shipper.selectedIndex == 0)
{
alert("The first \"Shipper\" option is not a valid selection. Please choose one of the other options.");
theForm.shipper.style.backgroundColor='pink';
theForm.shipper.focus();
return (false);
}}
return (true);
}
function chkFormTrack(form) {
var isChecked=0;
for (i=0;i<form.elements.length;i++) {
var obj = form.elements[i];
if (obj.type == 'checkbox') {
if (obj.checked == true) { isChecked++; }
}
if (isChecked > 0) {
return true;
}
}
if (isChecked > 0) { return true;}
else { alert('Please choose item(s) to attach.');
return false;
}
}
</script>