How to speed up a local validation process
Posted: Mon Oct 21, 2002 10:24 am
Dear folks,
I have a dynamically-built table form with up to 100 rows. Each row has two labels (a line number and a line description) and four text entry fields, where the user can enter numeric values (blanks are not accepted). The names of the four fields have a common prefix ("val") followed by one letter ("o", "r", "s" and "e" respectively) and the associated line number, so that the php post processing can fetch and handle the variables.
The local JavaScript validation function is the following:
The validation works fine except that, when the table is large, the time required to scan the whole form becomes excessively long (there are app. 400 elements to scan).
I have circumvented the problem by performing the validation in the php post processing (is_numeric() function) and, in case of error, going back to the form (history.go(-1)) which shows the original values, so that the user can correct the mistake and resubmit the form. This soulition seems faster than the JavaScript-based one.
Do you have any suggestions to further speed up this process?
Thank you,
Luca
I have a dynamically-built table form with up to 100 rows. Each row has two labels (a line number and a line description) and four text entry fields, where the user can enter numeric values (blanks are not accepted). The names of the four fields have a common prefix ("val") followed by one letter ("o", "r", "s" and "e" respectively) and the associated line number, so that the php post processing can fetch and handle the variables.
The local JavaScript validation function is the following:
Code: Select all
function formValidator()
{
for (var i = 0; i < document.form1.elements.length; i++)
{
if (document.form1.elementsїi].name.substr(0,3) == "val")
{
if (isNaN(document.form1.elementsїi].value) ||
document.form1.elementsїi].value.substr(0,1) == " ")
{
alert("Line " + document.form1.elementsїi].name.substr(4,4) + " not numeric");
document.form1.elementsїi].focus();
return false;
}
}
}
}I have circumvented the problem by performing the validation in the php post processing (is_numeric() function) and, in case of error, going back to the form (history.go(-1)) which shows the original values, so that the user can correct the mistake and resubmit the form. This soulition seems faster than the JavaScript-based one.
Do you have any suggestions to further speed up this process?
Thank you,
Luca