I have this chunk of code [sourced from different user on this site—thanks!] that I need to modify so that I can check multiple fields instead of just one. I'm not sure if I should be adding arguments to the second function or turn the variable checkString to an array.
function getField(fieldType, fieldTitle) {
var docTags = document.getElementsByTagName(fieldType);
for (var i = 0; i < docTags.length; i++) {
if (docTags[i].title == fieldTitle) {
return docTags[i]
}
}
}
function checkField() {
var checkString = getField('input', 'fieldtocheck').value;
if (checkString != "") {
if (/[^A-Za-z\d]/.test(checkString)) {
alert("Please enter only alphanumeric characters for the field fieldtocheck");
return (false);
}
}
}
I think the best option would be to feed "getfield" into the the "checkfield" as arguments but how would I do that?
Any help appreciated.