...

View Full Version : Functions Slowing Form Entry down



Chamark
12-05-2006, 03:11 AM
Is there some way to speed up the form entries when using JS? I have a scoring form that has 59 fields. Each question on the form is scored per response. The form reponse get slow as it is filled in. Can this code be optimized to improve entry response? Thanks for any help in advance!! :confused:

// function to total Scores for Customer Metrics
function startCalc(){
interval = setInterval("calc()",1);
}
function calc(){
one = document.form1.CM1score.value;
two = document.form1.CM2score.value;
three = document.form1.CM3score.value;
four = document.form1.CM4score.value;
five = document.form1.CM5score.value;
six = document.form1.CM6score.value;
seven = document.form1.CM7score.value;
eight = document.form1.CM8score.value;
nine = document.form1.CM9score.value;

document.form1.CMScore.value = (one * 1) + (two * 1) + (three * 1) + (four * 1) + (five * 1) + (six * 1) + (seven * 1) + (eight * 1) + (nine * 1) ;
}
function stopCalc(){
clearInterval(interval);
}


// function to total Scores for Business Metrics
function BMstartCalc(){
interval = setInterval("BMcalc()",1);
}
function BMcalc(){
one = document.form1.BM1score.value;
two = document.form1.BM2score.value;
three = document.form1.BM3score.value;
four = document.form1.BM4score.value;


document.form1.BMscore.value = (one * 1) + (two * 1) + (three * 1) + (four * 1) ;
}
function BMstopCalc(){
clearInterval(interval);
}

// function to total Scores for both customer & business Metrics
function TOTstartCalc(){
interval = setInterval("TOTcalc()",1);
}
function TOTcalc(){
one = document.form1.CMScore.value;
two = document.form1.BMscore.value;

document.form1.FinalScore.value = (one * 1) + (two * 1) ;
}
function TOTstopCalc(){
clearInterval(interval);
}

// function to update Scores when questions are answered
function CM1func(){
if (document.form1.CM1.value == "Yes") {
document.form1.CM1score.value = 2;
} else if (document.form1.CM1.value == "NA") {
document.form1.CM1score.value = 2;
} else if (document.form1.CM1.value == "NO") {
document.form1.CM1score.value = 0 ;
} else {
document.form1.CM1score.value = " ";

}
}
function CM2func(){
if (document.form1.CM2.value == "Yes") {
document.form1.CM2score.value = 2;
} else if (document.form1.CM2.value == "NA") {
document.form1.CM2score.value = 2;
} else if (document.form1.CM2.value == "NO") {
document.form1.CM2score.value = 0 ;
} else {
document.form1.CM1score.value = " ";

}
}
and so on and so on same type function - up to 15

brandonH
12-05-2006, 03:54 AM
looks to me like the problem is in the setInterval. you dont really need it. it'll keep running until you stop it. but if you are set on using the setInterval I would change the milliseconds amount to something higher, like say 50. most windows systems cant even perform a setInterval every 1 millisecond, but more around 10 milliseconds.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum