Results 1 to 2 of 2
  1. #1
    Star Lounger
    Join Date
    Jun 2009
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm trying to validate the minimum length of a field. I continue to receive an error (object doesn't support this property) with the below script:

    <html>
    <head>

    <script type="text/javascript">
    function validateContract()
    {
    var minLength = 6;
    var x=document.getElementById("contract").value;
    if (x.length < minLength) {
    alert('Contract must be ' + minLength + ' characters long. Try again.');
    return false;
    }
    }
    </script>

    </head>
    <body>
    Contract: <input type="text" id="contract" onblur="validateContract()" >
    </body>
    </html>

  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
    Works for me in IE7 and Fx3.5.9. I added a second field so I could tab to it to trigger the message, but otherwise, it's your code.

    Code:
    <html>
    <head>
    <script type="text/javascript">
    function validateContract()
    {
    var minLength = 6;
    var x=document.getElementById("contract").value;
    if (x.length < minLength) {
    alert('Contract must be ' + minLength + ' characters long. Try again.');
    return false;
    }
    }
    </script>
    </head>
    <body>
    Contract: <input type="text" id="contract" onblur="validateContract()" >
    More text: <input type="text" name="no2">
    </body>
    </html>

Posting Permissions

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