Hi,
Thanks for your inputs.
Am so sorry I couldn't reply earlier to your post.
Well....to update you on the latest on this problem I was able to solve one issue of checking all blank textboxes on my page.
While working on the same module a new condition has arise which is again giving me some headache.
Of the whole form two of my fields are as such that my form may get submitted even if any one of them is empty. However, if both the fields are empty my function should return back an alert stating "Any one of the two fields have to be filled".
-
<script language="JavaScript" type="text/javascript">
-
function checkfields(f1)
-
{
-
var inputs = f1.getElementsByTagName("input");
-
for(var i=0; i < inputs.length; i++)
-
{
-
if(inputs[i].type == "text" && inputs[i].className == 'required')
-
{
-
if(inputs[i].value=='')
-
{
-
alert("Please enter the Inventory Item");
-
inputs[i].focus();
-
return false;
-
}
-
}
-
}
-
}
-
</script>
-
This particular function is working perfectly fine but it checks for all fields to be filled in. My new condition requires it to OK page if any of the two fields are filled.
My input tags look like this
-
<form name="f1" method="GET" action="invsql.php" onsubmit="return checkfields(this)">
-
....
-
<td><input type="text" class="required" name="MAC<? echo $i; ?>" Id="MAC" /></td>
-
<td><input type="text" class="required" name="SerialNo<? echo $i; ?>" Id="SerialNo" /></td>
-
....
-
</form>
-
This is one of the things I tried
-
<script language="JavaScript" type="text/javascript">
-
function checkfields(f1)
-
{
-
var inputs = f1.getElementsByTagName("input");
-
for(var i=0; i < inputs.length; i++)
-
{
-
if(inputs[i].type == "text" && inputs[i].className == 'required')
-
{
-
if(document.getElementById('MAC').value=='' && document.getElementById('SerialNo').value=='')
-
{
-
alert("Please enter the Inventory Item");
-
inputs[i].focus();
-
return false;
-
}
-
}
-
}
-
}
-
</script>
-
However, contrary to my expectation that it'll check each row & hence would check MAC & SerialNo in each row by its Id it just checks for validation in first row & moves ahead even if rest all MAC & SerialNos remain empty.
As again .. I'm working on Php with Mysql & problem is valid for Both IE & FireFox.
I think the problem is I'm not able to somehow make it check each row at a time though being in a loop it should be doing that.
I would appreciate if anybody could help.