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
    Apr 2009
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Javascript Form Validation Code - not working in IE7

    Hi there,

    Can someone take a look at the following javascript code for form validation - it's working great in Firefox, Safari & Opera however, it doesn't work in IE7 although the form can still be used and submitted etc, it doesn't prompt when a field is left blank.

    Here's the url:

    http://www.saponelawfirm.com/contact.html

    What do I need to do in order to make it work in IE7?

    Many, many thanks!

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    It's not working in FF2 either. I don't see any validation script on your site.

    Edit: Sorry, I missed it.
    Last edited by abduraooft; 04-08-2009 at 10:20 AM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,664
    Thanks
    80
    Thanked 4,640 Times in 4,602 Posts
    HUH? The validation is right there in the file. Code such as:
    Code:
    			function validate(){
    				var form=this
    				clearErrors(form)
    				shrinkMyFields(form)
    				if (form.FirstName.value.match(justWhiteSpace)) error(form.FirstName,"First name is required.")
    				if (form.LastName.value.match(justWhiteSpace)) error(form.LastName,"Last name is required.")
    				if (!form.email.value.match(validEmail)) error(form.email,"Please enter a valid email address.")
    				if (form.comments.value.match(justWhiteSpace)) error(form.comments,"A comment is required.")
    				return noErrors()
    			}
    It certainly is a very complex set of validation for such a simple little form, so I assume it's some sort of generic code lifted en masse for the purpose.

    It works, mostly, in FF3. I had it submit the form one time even though I had no email address given. A glitch of some kind.

    AHHH! Found it.

    MSIE says "object does not support this property or method" for the line:
    Code:
    	for(var errorFields=form.getElementsByClassName('error-present'),i=errorFields.length-1;i>=0;i--){
    And, indeed, the MSIE reference docs do *NOT* list getElementsByClassName as a method, anyplace.

    So...back to the drawing board, a little. Should be easy enough to work around this. Get all the relevant elements by some other means (by tag name?) and then just check the .className property for a match.

  • Users who have thanked Old Pedant for this post:

    Fun Leprechaun (04-09-2009)


  •  

    Posting Permissions

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