...

View Full Version : return onsubmit



nikko50
04-23-2008, 03: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>

nikko50
04-23-2008, 03:10 PM
What I would like to do is combine the chkFormTrack(form) function within the validateTracking function. How can this be done?

chump2877
04-23-2008, 04:37 PM
Does this work?


onsubmit="if (!validateTracking(this) || !chkFormTrack(this)) return false;"



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum