Looping through an array of input boxes (SOLVED)
I have a date validation function which I'd like to extend for checking multiple date fields on one page (instead of copying and pasting the same function renamed for each seperate date field)..
The problem I have is looping through an array of date field names. I need to use the array value to get the input box value and then validate. Here's a dumbed down version the form and javascript below:
EDITED:
This function solved the problem:
The problem I have is looping through an array of date field names. I need to use the array value to get the input box value and then validate. Here's a dumbed down version the form and javascript below:
<script type="text/javascript">The error is that 'datefields is null or not a value'. Any idea why or how to over come it?
function CheckForm(theForm)
{
var datefields = new Array();
datefields[0] = 'BIRTHDT';
datefields[1] = 'DTXFUS';
datefields[2] = 'RECALL_DATE';
datefields[3] = 'TREATMENT_DATE';
datefields[4] = 'DX_DATE';
for ( fieldName in datefields )
{
fn = new String(theForm.datefields[fieldName].value);
alert(fn);
}
}
</script>
<form onsubmit='javascript: return CheckForm(this);'>
<input type=text name='BIRTHDT' value=123><br>
<input type=text name='DTXFUS' value=777><br>
<input type=text name='RECALL_DATE' value=555><br>
<input type=text name='TREATMENT_DATE' value=444><br>
<input type=text name='DX_DATE' value=333><br>
<input type=submit>
</form>
EDITED:
This function solved the problem:
function CheckForm(theForm)
{
var datefields = new Array();
var e = document.frmAdd.elements;
datefields[0] = 'BIRTHDT';
datefields[1] = 'DTXFUS';
datefields[2] = 'RECALL_DATE';
datefields[3] = 'TREATMENT_DATE';
datefields[4] = 'DX_DATE';
for ( fieldName in datefields )
{
var fn = e[datefields[fieldName]].value;
alert(fn);
}
} 