dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: Form Validation Limit?

  1. #1
    Join Date
    May 2004
    Posts
    2

    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;
    }

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    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 for loop instead a long sausage in your code.

  3. #3
    Join Date
    May 2004
    Posts
    2
    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.

  4. #4
    Join Date
    May 2004
    Location
    St. Louis, Missouri, USA
    Posts
    164
    For the last 10 elements, why do your return true if it is blank?? What are you trying to acheive by doing this??

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles