Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Strange Validation ISSUE

    Hi,

    I have on my local machines IE10; at the client location they are running IE10 and we both have the exact same version all updated.

    On my machines here I can run the pages without any errors and the validation works no problems.

    Same Browser and OS on the client machines is giving JavaScript errors and the code won’t work.

    Strongly enough the line “form.Addr1.value.length” passes no problems; but if fails at “else if (form.City.length < 1) {” with an error of “Error: Unable to get property 'length' of undefined or null reference”

    REMEMBER THIS ERROR IS NOT HAPPENING ON MY MACHINES, only on the client machines; all of them.

    <JavaScript Code>

    <script type="text/javascript">

    // Mike Belcher - mbdev@outlook.com - Post to the SendCustomerLetter.aspx page

    function SubmitSendCustomerLetter() {

    // GET THE VALUES WE NEED AND DO VALIDATION

    var form = document.getElementById("OOStitleForm");

    if (form.Addr1.value.length < 1) {

    alert("Please Enter an Address")

    form.Addr1.focus()

    return false

    }

    else if (form.City.length < 1) {

    alert("Please Enter a City")

    form.City.focus()

    return false

    }

    else if (form.CorrespTitleState.length < 1) {

    alert("Please Select a State")

    form.CorrespTitleState.focus()

    return false

    }

    else if (form.Zip.length < 1) {

    alert("Please Enter a Zipcode")

    form.Zip.focus()

    return false

    }

    else {

    //alert("Validation Has Passed; lets run the code")

    // Here we do the post

    form.action = 'SendCustomerLetter.aspx';

    form.target = 'SendCustomerLetterCorrespondence';

    form.submit();

    //return true

    }

    }

    </script>
    </JavaScript Code>

    <html>

    <table border='0' cellpadding='2' width='100%' id='CorrespondanceMenu'>

    <tr>

    <td width='150' align='right'>Customer Addr 1 </td>

    <td width='346'><input name='Addr1' type='text' id='Addr1' value='12345 The Matrix' style='color:#0066FF;width:254;height:22' size='50' /></td>

    <td width='368'>

    <div align='left'>

    <table border='0' cellpadding='0' width='100%' cellspacing='0'>

    <tr>

    <td width='50'>Phone</td>

    <td width='159'><input name='Phone1' type='text' id='Phone1' value='410-123-4321' style='color:#0066FF;width:140;height:22' size='25' /></td>

    <td width='29'>

    <input type='button' name='PhoneCall' id='PhoneCall' value='Phone Call' onClick="SubmitPhoneSimple();">

    <input type='hidden' name='TitleID' value='1946'/></form>

    </tr></table>

    </div>

    </td>

    </tr>

    <tr>

    <td width='150' align='right'>Customer Addr 2 </td>

    <td width='346'><input name='Addr2' type='text' id='Addr2' value='HBO and other movie channels' style='color:#0066FF;width:254;height:22' size='50' /></td>

    <td width='29'>

    <input type='button' name='SendCustomerLetter' id='SendCustomerLetter' value='Send Customer Letter' onClick="SubmitSendCustomerLetter();">

    </tr>

    <tr>

    <td width='116' align='right'>City </td>

    <td colspan='2'>

    <div align='left'>

    <table border='0' cellpadding='0' width='84%' cellspacing='0'>

    <tr>

    <td width='152'><input name='City' type='text' id='City' value='Matrixville' style='color:#0066FF;width:140;height:22' size='30' /></td>

    <td width='38'> State </td>

    <td width='68'>

    <select name='CorrespTitleState' id='CorrespTitleState' style='color:#0066FF;'>

    <option value='FL' selected>FL</option>

    <option value='AK'>AK</option>

    <option value='AL'>AL</option>

    <option value='AR'>AR</option>

    <option value='AZ'>AZ</option>

    <option value='CA'>CA</option>

    <option value='CO'>CO</option>

    <option value='CT'>CT</option>

    <option value='DE'>DE</option>

    <option value='FL'>FL</option>

    <option value='GA'>GA</option>

    <option value='HI'>HI</option>

    <option value='IA'>IA</option>

    <option value='ID'>ID</option>

    <option value='IL'>IL</option>

    <option value='IN'>IN</option>

    <option value='KS'>KS</option>

    <option value='KY'>KY</option>

    <option value='LA'>LA</option>

    <option value='MA'>MA</option>

    <option value='MD'>MD</option>

    <option value='ME'>ME</option>

    <option value='MI'>MI</option>

    <option value='MN'>MN</option>

    <option value='MO'>MO</option>

    <option value='MS'>MS</option>

    <option value='MT'>MT</option>

    <option value='NC'>NC</option>

    <option value='ND'>ND</option>

    <option value='NE'>NE</option>

    <option value='NH'>NH</option>

    <option value='NJ'>NJ</option>

    <option value='NM'>NM</option>

    <option value='NV'>NV</option>

    <option value='NY'>NY</option>

    <option value='OH'>OH</option>

    <option value='OK'>OK</option>

    <option value='OR'>OR</option>

    <option value='PA'>PA</option>

    <option value='RI'>RI</option>

    <option value='SC'>SC</option>

    <option value='SD'>SD</option>

    <option value='TN'>TN</option>

    <option value='TX'>TX</option>

    <option value='UT'>UT</option>

    <option value='VA'>VA</option>

    <option value='VT'>VT</option>

    <option value='WA'>WA</option>

    <option value='WI'>WI</option>

    <option value='WV'>WV</option>

    <option value='WY'>WY</option>

    </select></td>

    <td width='32' align='right'>Zip </td>

    <td width='148'><input name='Zip' type='text' id='Zip' value='21229' style='color:#0066FF;width:140;height:22' size='10' /></td>

    <td> </td>

    </tr>

    </table>

    </div>

    </td>

    </tr>

    </table>

    </html>

    Makes no sense why the same browser on two different systems, one has errors and the other has none.

    Any Ideas?

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,017
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    <input type='hidden' name='TitleID' value='1946'/></form>

    The </form> tag is wrongly positioned, and I do not see any opening <form> tag.

    Form validation of the pattern if (document.formname.formfield.length <1) - that is blank - is barely worthy of the name, and virtually useless, as even a single space, an X or a ? will return false, that is pass the validation. A proper name may only contain letters, hyphen, space and apostrophe.
    Numeric values, such as zip codes, phone numbers and dates, should be validated as such. Ditto email addresses. This topic has been covered many times before in this forum.

    alerts are obsolete as a way of displaying a message to the user. Use DOM methods instead.


    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,553
    Thanks
    78
    Thanked 4,382 Times in 4,347 Posts
    You know, *YOU* gave the entire reason for the failure in your description of it:
    ... enough the line “form.Addr1.value.length” passes no problems; but if fails at “else if (form.City.length < 1) ...
    You can't get the length of a form field! You must get the length of the .value of the form field.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Tags for this Thread

    Posting Permissions

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