setInterval with Parameters

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • somebody
    New Member
    • Jan 2008
    • 1

    setInterval with Parameters

    So I've got this code:

    [HTML]function startCalc(one, two, three){
    interval = setInterval(cal c(one, two, three),1);
    }

    function calc(one, two, three){
    var element = document.getEle mentById(one).v alue;
    var element2 = document.getEle mentById(two).v alue;
    document.getEle mentById(three) .value = (element * 1) * (element2 * 1);
    }

    function stopCalc(){
    clearInterval(i nterval);
    }[/HTML]

    Now, calc is being ran without the interval because it doesn't have quotes. However, if I put quotes in, the parameters aren't passed and the function doesn't work. What can I do? Thanks in advance for your help.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Welcome to TSDN!

    You will need to quote the arguments:
    [code=javascript]function startCalc(one, two, three){
    interval = setInterval("ca lc('"+one+"', '"+two+"', '"+three+"')",1 );
    }[/code]

    Comment

    Working...