|
-
May 29th, 2003, 02:51 PM
#1
Thread Starter
Fanatic Member
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;
}
-
May 30th, 2003, 09:24 AM
#2
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 : 
-
May 30th, 2003, 09:27 AM
#3
Thread Starter
Fanatic Member
Thanks, I appreciate that. When return true is in there, it is just returning a boolean value of true?
-
May 30th, 2003, 09:39 AM
#4
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 : 
-
Jun 2nd, 2003, 01:49 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|