Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Nov 2006
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •