Results 1 to 5 of 5

Thread: Validation

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954

    Validation

    OK, I am trying to check for blank fields in all of the input tags, also if the tag has the word 'other' in it, I am disregarding the check. THe issue is that it gets to 0 in the for loop and bombs. below:

    Code:
    var inputFields = document.all.tags("INPUT") //grabs all input tags
    for(i=0; i < inputFields.length; i++)
    {
    	if (inputFields[i].value == '')
    	{
    		alert("Checking " + inputFields[i].name.substr(3,5));
    		if(inputFields[i].name.substr(3, 5) != 'other')
    		{
    		alert('Please fill out '+ inputFields[i].name);
    		inputFields[i].name.focus
    		return false;
    		break;
    		}
    	return true;
    	}
    return true;
    }

  2. #2
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Take out the two return true statement.

    Heres is how u should do it.

    Code:
    <html>
    <head>
    <script>
    
    function validate()
    {
    	var inputFields = document.all.tags("INPUT") //grabs all input tags
    	for(i=0; i < inputFields.length; i++)
    	{
    		if (inputFields[i].value == '')
    		{
    			alert("Checking " + inputFields[i].name.substr(3,5));
    			if(inputFields[i].name.substr(3, 5) != 'other')
    			{
    			alert('Please fill out '+ inputFields[i].name);
    			inputFields[i].name.focus
    			return false;
    			break;
    			}
    
    		}
    
    	}
    }
    </script>
    </head>
    
    <body>
    <form name=form1>
    <input type=textbox name=i1 size="20">
    <br>
    <input type=textbox name=i2 size="20">
    <br>
    <input type=textbox name=i3 size="20">
    <br>
    
    <input type=button value=submit onclick="JavaScript:validate()">
    </form>
    </body>
    </html>
    Hope this helps

    Danial
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    Thanks, I appreciate that. When return true is in there, it is just returning a boolean value of true?

  4. #4
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Originally posted by brianh
    Thanks, I appreciate that. When return true is in there, it is just returning a boolean value of true?
    yes it is, and thats why the full loop was not being processed and it was acting as break statement.

    Danial
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    If you're willing to give up IE4 support in favor of Gecko support you should change the script:
    Code:
    function validate()
    {
    	var inputFields = document.getElementsByTagName("INPUT") //grabs all input tags
    	for(i=0; i < inputFields.length; i++)
    	{
    		if (inputFields[i].value == '')
    		{
    			alert("Checking " + inputFields[i].name.substr(3,5));
    			if(inputFields[i].name.substr(3, 5) != 'other')
    			{
    			alert('Please fill out '+ inputFields[i].name);
    			inputFields[i].focus();
    			return false;
    			break;
    			}
    
    		}
    
    	}
    }
    It's not as if
    inputFields[i].name.focus
    had any effect anyway.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

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



Click Here to Expand Forum to Full Width