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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Javascript's "while" loop in function, have an error somewhere.

    First post here so...

    I have a few functions called by a form. Two examples are onclick in a form input and onkeyup in a form button.


    Code:
    function checkUsernameForLength(whatYouTyped) {
    	var fieldset = whatYouTyped.parentNode;
    	var txt = whatYouTyped.value;
    	if (txt.length > 2) {
    		fieldset.className = "welldone";
    		return true;
    	}
    	else {
    		fieldset.className = "";
    		return false;
    	}
    }
    Code:
    onkeypress="checkUsernameForLength(this);"
    There are a couple of the above "validation" functions. Each sets an input fieldset's class.


    Code:
    function verifyit() {
       var fieldsets = document.getElementsByTagName("fieldset");
       var i=0;
       while (i<count(fieldsets)){
       if (fieldsets[i] != "") {	   
       i++;
       document.form.submit();      
        }	
        }
        }
    Code:
    onclick="verifyit()"
    The function above is where I'm having the trouble. I want to iterate through the fieldsets and make sure each class isn't blank before allowing the button to submit the form. I get an "object expected" error when I trigger the "verifyit" function with ie if it helps.

    I appreciate any input, thanks in advance for any help.

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,133
    Thanks
    12
    Thanked 332 Times in 328 Posts
    which line exactly throws that error?

    there is also a problem with your submit logic …
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

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