Results 1 to 4 of 4
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    what's wrong with this javascript?

    I am still working on this but am starting to slide into flail mode <img src=/S/flee.gif border=0 alt=flee width=25 height=25>

    The code is supposed to inspect a field and do the following:
    1) if the field is empty, prompt alert that field has to be entered, set focus and block submit
    2) if the field is not empty, inspect format and alert if field is not in correct format, set focus and block submit
    3) if both conditions are satisfied, return true (allow submit)

    <font face="Georgia">
    function validateForm(theForm)
    {
    if (!requiredField(theForm.Comp_Date_Completed, "Date Completed"))
    {
    return false;
    }
    else
    {
    if (!validDate(theForm.Comp_Date_Completed, "Date Completed"))
    {
    return false;
    }
    }

    if (!validDate(theForm.Comp_Date_Completed, "Date Completed"))
    {
    return false;
    }

    }
    </font face=georgia>

    I've written about the general project in another thread (YAVQ) but that was getting long, and I'm thinking, maybe, a solution to this part of the main validation function might help with the rest.

    TIA <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23>

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: what's wrong with this javascript?

    What is the code for the two functions you're calling here?

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: what's wrong with this javascript?

    since posting this I re-wrote the javascript to the point where it basically works. I wanted to do the following:

    1) validPhone function
    2) validDate function
    3) requiredField function
    4+ ... any other functions

    and call these using validateForm(theForm)

    What I ended up doing was loading another variable into validDate() to test for required field based on a value passed to the function when called. This still showed the same problem I've been having forever, viz., if the first function call in the validateForm(theForm) is not tested, none of the others are.

    So I did something counter-intuitive: in my list of function calls (NOT nested ifs, no ELSE or anything else -- just a series of IF tests) I noticed I have validDate(FIELD1) and then validDate(FIELD2) then validPhone(FIELD) ... validPhone(FIELDn). I moved the second validPhone(FIELD2) to the end of the list of tests and, voila! the durn thing works. Don't ask me why. In the code I feel like using the classic comment * You are not expected to understand this * <img src=/S/aussie.gif border=0 alt=aussie width=21 height=22>

    If you want to look at the whole thing I can post the page back.

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: what's wrong with this javascript?

    > If you want to look at the whole thing I can post the page back.

    Um, no thanks. I've had my fill. <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15> I'm just glad to hear it's working now.

Posting Permissions

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