Web Analytics Made Easy -
StatCounter form validation headache - CodingForum


No announcement yet.

form validation headache

  • Filter
  • Time
  • Show
Clear All
new posts

  • form validation headache

    hey y'all

    am busy writing a form validation script and i keep coming up against this problem. Here's the sc:

    function checkValidation(formID, fieldID)
    // this alerts the ACTUAL document object -
    // displays correct inputted value
    alert("formID : "+formID+" fieldID : "+fieldID);
    // this alerts the vales of the variables that will
    // be used to build the virtual document object
    // this alerts with the correct values passed to the function

    fieldVal = document.formID.fieldID.value;
    // *this assigns the value of the virtual document object
    // *to be used in other validation functions -
    // *this is where i get errors - see below:
    if (fieldVal){checkElementNoSpace(fieldVal);}}
    // value passed to new function

    *error: i get an error of "'document.formID.fieldID.value' is not an object" - anybody got any ideas? Have I got the syntax wrong?

    thanx - have a good day!!

    code, debug, dubug, debug, *SIGH* debug, debug ...

  • #2

    Sorry about that - I invoke the funtion throug an onChange event - ie:

    <input class="formField" type="text" name="Title" size="50" onChange="checkValidation('RequestForInformation','Title')">

    The two values passed are the form name (RequestForInformation) and the element name (Title)

    Does that help?


    code, debug, dubug, debug, *SIGH* debug, debug ...


    • #3
      Hi there!

      Cheers for the suggestion Dave - that guesswork was right on the money on your part - nice one!

      Now - another problem. I've been toying arounf with the function call and have changed it from "onChange=(<call validation function>)" to "onBlur=(<call validation function>)" : is there any reason why I should not be using this?

      Another issue that I have is the actual validation itself. The function will work correctly if there is a blank space in the form field, but not if nothing at all is entered. I've tried testing for this using a null value check, but it doesn't seem to pick it up. Here's the sc:

      function checkElementNoSpace(value)
      { alert(value)
      //alerts the passed value fine!

      if ((value == null) || (value == " "))
      //does the check for " " but not the null - have tried
      //"null" and 'null' as well as reversing the order of the operands
      //and inverting the logic of the if statement - none to any avail

      { alert("Please enter a value!");
      return false; }
      { return true; }}

      This function is called from the function above, to whit:

      function checkValidation(formID, fieldID)
      {fieldVal = document.forms[formID].elements[fieldID].value;
      if (fieldVal){return checkElementNoSpace(fieldVal);}}

      Which is called from the html by:

      <input class="formField" type="text" name="Title" size="50" onBlur="checkValidation('RequestForInformation','Title')">

      Anybody have any ideas? I'm sure it's got something to do with the logic in the checkElementNoSpace function, but I don't know what it is...


      code, debug, dubug, debug, *SIGH* debug, debug ...