Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-05-2006, 02:11 AM   PM User | #1
Chamark
New Coder

 
Join Date: Nov 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Chamark is an unknown quantity at this point
Functions Slowing Form Entry down

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!!

// 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
Chamark is offline   Reply With Quote
Old 12-05-2006, 02:54 AM   PM User | #2
brandonH
Regular Coder

 
Join Date: Oct 2003
Location: on a ship
Posts: 574
Thanks: 1
Thanked 6 Times in 5 Posts
brandonH is on a distinguished road
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.
__________________
I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.
brandonH is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:00 PM.


Advertisement
Log in to turn off these ads.