Jump to content

Archived

This topic is now archived and is closed to further replies.

paolinaaaaaaa

script works in firefox but not in explorer

Recommended Posts

Hi everyone I adapted this little script to make a dynamic sum of values inserted in a list box. However I can only get it to work in firefox but not in explorer. Can anyone tell me why? thanx!

[hr]
//in the head of my document:

<script type ="text/javascript">
<!-- Begin
function startCalc(){
  interval = setInterval("calc()",1);
}
function calc(){
  one = document.form.comm.value;
  two = document.form.cost.value;
  three = document.form.hres.value;
  four = document.form.qual.value;
  five = document.form.scop.value;
  six = document.form.time.value;
  document.form.total.value = (one * one) + (two * two) + (three * three) + (four * four) + (five * five) + (six * six);
 
  }
function stopCalc(){
  clearInterval(interval);
}
//  End -->
</script>

//in the body

<select name='comm' size ='1' onFocus="startCalc();" onBlur="stopCalc();">
<option selected='selected'>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
<select name='cost' size ='1' onFocus="startCalc();" onBlur="stopCalc();">
<option selected='selected'>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
<select name='hres' size ='1' onFocus="startCalc();" onBlur="stopCalc();">
<option selected='selected'>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
<select name='qual' size ='1' onFocus="startCalc();" onBlur="stopCalc();">
<option selected='selected'>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
<select name='scop' size ='1' onFocus="startCalc();" onBlur="stopCalc();">
<option selected='selected'>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
<select name='time' size ='1' onFocus="startCalc();" onBlur="stopCalc();">
<option selected='selected'>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>

Share this post


Link to post
Share on other sites
the "interval" variable is a local variable to the startCalc() function. You need to make it global like this
[code]
<!-- Begin
var interval = "";
[/code]

Share this post


Link to post
Share on other sites
oh yeah, you are missing the values in your options
[code]
<option selected='selected' value=0>0</option>
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=5>5</option>
[/code]
notice how I added "value=#" in the option.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.