function validateForm_addCase_form(formObject,numClaimants) {
alertText = "";
for(i=0;i<numClaimants;i++) {
fieldName = i + "_claimant_ssn";
if(formObject.elements[fieldName].value.length > 0) {
//strip out all non-numeric characters
formObject.elements[fieldName].value = formObject.elements[fieldName].value.replace(/[^0-9]/g, '');
if(formObject.elements[fieldName].value.length != 9) {
alertText += "Please enter a valid, 9-digit Social Security Number for Claimant Number " + (i + 1) + ".\n";
}
else {
formObject.elements[fieldName].value = formObject.elements[fieldName].value.substring(0,3) + "-" + formObject.elements[fieldName].value.substring(3,5) + "-" + formObject.elements[$ieldName].value.substring(5,9);
}
}
else {
//do nothing related to ssn, because nothing was entered and it's not required
}
}
Works fine on FF, but not IE. Any idea why? If I alert(formObject.elements[fieldName].name), it gives me the names of the first i (counter) fields in the form, rather than the first i fields that follow the i_claimant_ssn naming. Again, works as expected on FF. I hate IE!
Does anyone know of one way that works for both? Or, will I have to check the browser type each time? I find it hard to believe that such a simple task is not supported congruently in both browsers.
function validateForm_addCase_form(formObject,numClaimants) {
alertText = "";
//deal with claimant_ssn(s)
for(i=0;i<numClaimants;i++) {
fieldName = i.toString() + "_claimant_ssn";
if (navigator.appName == "Netscape") {
field = formObject.elements[fieldName]; //ff
}
if (navigator.appName == "Microsoft Internet Explorer") {
field = formObject(fieldName); //ie
}
if(field.value.length > 0) {
//strip out all non-numeric characters
field.value = field.value.replace(/[^0-9]/g, '');
if(field.value.length != 9) {
alertText += "Please enter a valid, 9-digit Social Security Number for Claimant Number " + (i + 1) + ".\n";
}
else {
field.value = field.value.substring(0,3) + "-" + field.value.substring(3,5) + "-" + field.value.substring(5,9);
}
}
else {
//do nothing related to ssn, because nothing was entered and it's not required
}
}
Also, did anyone know that "navigator.appName" returns "Netscape" for FF? Thought that was strange.