By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,948 Members | 1,975 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,948 IT Pros & Developers. It's quick & easy.

setInterval with Parameters

P: 1
So I've got this code:

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

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

function stopCalc(){
clearInterval(interval);
}[/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.
Jan 15 '08 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
Welcome to TSDN!

You will need to quote the arguments:
Expand|Select|Wrap|Line Numbers
  1. function startCalc(one, two, three){
  2.     interval = setInterval("calc('"+one+"', '"+two+"', '"+three+"')",1);
  3. }
Jan 15 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.