Working on IE but not Firefox

Hi, I’m having trouble figuring out why this code works on IE but not Firefox. I’m pretty sure the checkRes works, cause it updates how many resources are left but when you click “Auto-Split”, it doesn’t auto split them in Firefox.

Basicly, the script divides resources that a player’s kingdom has.


<SCRIPT LANGUAGE="JavaScript" type="text/javascript">
<!-- Begin

  function checkRes(limitCount, limitNum) {

    res = document.getElementsByName("res[]");

    food = parseInt(res[0].value);
    gold = parseInt(res[1].value);
    wood = parseInt(res[2].value);
    stone = parseInt(res[3].value);

    if(!food){ food=0; }
    if(!gold){ gold=0; }
    if(!wood){ wood=0; }
    if(!stone){ stone=0; }

    total = food+gold+wood+stone;

	limitCount.value = limitNum - total;
  }

  function splitRes() {

     res = document.getElementsByName("res[]");
     total = document.getElementById("countdown");
     total = parseInt(total.value);

     split = total/4;
     down = Math.floor(split);
     left = (split-down)*4;
     split = Math.floor(split);

     food = parseInt(res[0].value);
     gold = parseInt(res[1].value); 
     wood = parseInt(res[2].value);
     stone = parseInt(res[3].value);

     if(!food){ food=0; }
     if(!gold){ gold=0; }
     if(!wood){ wood=0; }
     if(!stone){ stone=0; }

     res[0].value=food+split+left;
     res[1].value=gold+split;
     res[2].value=wood+split;
     res[3].value=stone+split;



     checkRes(document.aaform.countdown,<?=$totalRes?>);
  }

//  End -->
</script> 

The Html Part

<form method="post" action="goodies.php" name="aaform">
<input type="text" class="input" size="5" name="res[]" onKeyDown="checkRes(this.form.countdown,<?=$totalRes?>);" onKeyUp="checkRes(this.form.countdown,<?=$totalRes?>);"></td>
<input type="text" class="input" size="5" name="res[]" onKeyDown="checkRes(this.form.countdown,<?=$totalRes?>);" onKeyUp="checkRes(this.form.countdown,<?=$totalRes?>);"></td>
<input type="text" class="input" size="5" name="res[]" onKeyDown="checkRes(this.form.countdown,<?=$totalRes?>);" onKeyUp="checkRes(this.form.countdown,<?=$totalRes?>);"></td>
<input type="text" class="input" size="5" name="res[]" onKeyDown="checkRes(this.form.countdown,<?=$totalRes?>);" onKeyUp="checkRes(this.form.countdown,<?=$totalRes?>);"></td>
Resources Left: <input readonly type="text" name="countdown" size="10" value="<?=$totalRes?>"> <a href="#" onClick="splitRes()">Auto-Split</a>
</form>

I found the problem I was using getElementById() method, but my element has no id, has only a name.

“IE, incorrectly, is able to take the name as id, if the id is missing. Not the full compliant browsers, as id and name are different attributes.”

Changed the element name to an id for “countdown”