/    Sign up×
Community /Pin to ProfileBookmark

Form Validation Limit?

I have a javascript form validation function with 13 checks in it. The function stops after 7 checks. I have swapped the order, taken some out, etc & they all work fine individually, but together it goes through about 7 and then exits the function and submits the form. Are there limits on functions?

Thank you so much for any help you can give me!

Here is the validation function in case it helps:

function validateform ( )
{
valid = true;

if ( document.mainform.EventNum.value == “” )
{
alert ( “Please fill in the Event Number” );
valid = false;
document.mainform.EventNum.focus();
return false;
}

valid = true;

if ( document.mainform.SiteDes.options[0].selected )
{
alert ( “Please fill in the Site Designation” );
valid = false;
document.mainform.SiteDes.focus();
return false;
}

valid = true;
if ( document.mainform.Date.value == “” )
{
alert ( “Please fill in the Date” );
valid = false;
document.mainform.Date.focus();
return false;
}

valid = true;

if ( document.mainform.ActTimeOn.value == “” )
{
return true;
}
else {if ( document.mainform.ActTimeOn.value.length != 4 )
{
alert( “Please Fill in a 4 Digit Actual Time On” );
valid = false;
document.mainform.ActTimeOn.focus();
return false;
}
}

valid = true;

if ( document.mainform.StartTime.value == “” )
{
return true;
}
else {if ( document.mainform.StartTime.value.length != 4 )
{
alert( “Please Fill in a 4 Digit Start Time” );
valid = false;
document.mainform.StartTime.focus();
return false;
}
}
valid = true;

if ( document.mainform.EndTime.value == “” )
{
return true;
}
else {if ( document.mainform.EndTime.value.length != 4 )
{
alert( “Please Fill in a 4 Digit End Time” );
valid = false;
document.mainform.EndTime.focus();
return false;
}
}

valid = true;

if ( document.mainform.SchedTimeOn.value == “” )
{
return true;
}
else {if ( document.mainform.SchedTimeOn.value.length != 4 )
{
alert( “Please Fill in a 4 Digit Scheduled Time On” );
valid = false;
document.mainform.SchedTimeOn.focus();
return false;
}
}

valid = true;

if ( document.mainform.SchedTimeOff.value == “” )
{
return true;
}
else {if ( document.mainform.SchedTimeOff.value.length != 4 )
{
alert( “Please Fill in a 4 Digit Scheduled Time Off” );
valid = false;
document.mainform.SchedTimeOff.focus();
return false;
}
}

valid = true;

if ( document.mainform.ActTimeOff.value == “” )
{
return true;
}
else {if ( document.mainform.ActTimeOff.value.length != 4 )
{
alert( “Please Fill in a 4 Digit Actual Time Off” );
valid = false;
document.mainform.ActTimeOff.focus();
return false;
}
}

valid = true;

if ( document.mainform.OverStart.value == “” )
{
return true;
}
else {if ( document.mainform.OverStart.value.length != 4 )
{
alert( “Please Fill in a 4 Digit Overtime Start Time” );
valid = false;
document.mainform.OverStart.focus();
return false;
}
}

valid = true;

if ( document.mainform.OverStop.value == “” )
{
return true;
}
else {if ( document.mainform.OverStop.value.length != 4 )
{
alert( “Please Fill in a 4 Digit Overtime Stop Time” );
valid = false;
document.mainform.OverStop.focus();
return false;
}
}
valid = true;

if ( document.mainform.SchedStop.value == “” )
{
return true;
}
else {if ( document.mainform.SchedStop.value.length != 4 )
{
alert( “Please Fill in a 4 Digit Scheduled Stop Time” );
valid = false;
document.mainform.SchedStop.focus();
return false;
}
}
valid = true;

if ( document.mainform.SchedStart.value == “” )
{
return true;
}
else {if ( document.mainform.SchedStart.value.length != 4 )
{
alert( “Please Fill in a 4 Digit Scheduled Start Time” );
valid = false;
document.mainform.SchedStart.focus();
return false;
}
}
valid = true;
}

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@KorMay 25.2004 — I don't know why is that limit but you should definitely change your script. Better reffere the form's elements using rather their type & order than their name or id. Thus you will be able to use a [b]for[/b] loop instead a long sausage in your code.
Copy linkTweet thisAlerts:
@stefaniauthorMay 25.2004 — I am not sure how to do that since I don't want to loop through all the form fields - only certain ones, so I couldn't just increment the index after each loop.
Copy linkTweet thisAlerts:
@theBody44May 25.2004 — For the last 10 elements, why do your return true if it is blank?? What are you trying to acheive by doing this??
×

Success!

Help @stefani spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...