Firefox, IE, DOM/Javascript Issue

jimi_81

OSNN Senior Addict
Political Access
Joined
29 May 2002
Messages
820
Hey guys..
I've thrown together a script that only works in IE.. because I use document.elements to sum form values.

Firefox doesnt like that. Firefox needs document.getElementsbyID
I have no idea how to implement this...

Code:
  <script>
  function addscore".$teamid."(obj)
  {
   var total = 0;
   var tmp=0;
   for (i=0; i< enterscore.elements['".$pstat."'].length; i++)
   {
    tmp =Number(enterscore.elements['".$pstat."'][i].value);
    total = Number(total + tmp);
   } 
   enterscore.totgoals".$teamid.".value=total; 
  } 
  </script>

With input fields:
Code:
<Input TYPE='text' NAME='$pstat' value='0' onChange = 'addscore".$teamid."(this)' onblur = 'submitForms".$teamid."(this)' MAXLENGTH='2' SIZE='2'>

$pstat is a variable...$pstat = "player_stat_goals03[]";

My question is probably not as simple as.. how do I implement this to work in firefox. I tried changing the NAME to ID, but that pretty much did nothing. When I look at javascript and DOM I get a headache instantly. Is there any OSNN'r around that feels comfortable it?

thanks for any help!
 
PHP:
<?

$teamid="team1";
$pstat="player_stat_goals03";

  print 
  "<script>
  function addscore".$teamid."(obj)
  {
   var total = 0;
   var tmp=0;
   for (i=0; i< parseInt(obj.value.length); i++)
   {
    tmp =parseInt(obj.value[i]);
    total = parseInt(total + tmp);
   } 
   window.alert(total); // changed for testing
  } 
  </script>
  ";

print 
"
<Input TYPE='text' id='$pstat' value='10' onChange = 'addscore".$teamid."(this)' onblur = 'submitForms".$teamid."(this)' MAXLENGTH='2' SIZE='2'>
";

?>

Does this do what you want?

http://albybum.net/temp/test.php
 
I'm going to try the idea out, but man, because you put in the effort, i gotta rep you. thanks for taking the time man!
 
Looking back over the original code, I don't think my answer did what you wanted.

I think this does. Full page example.
http://www.albybum.net/temp/test.php

PHP:
<html>
<head>
<?
$teamid="team1";
$pstat="player_stat_goals03";
print 
"<script>
function addscore".$teamid."(obj)
{
var total = 0;
var tmp=0;
var es='';
es=document.getElementsByName('$pstat');
 
for (i=0; i< parseInt(es.length); i++)
{
tmp =parseInt(es[i].value);
total = parseInt(total + tmp); 
}
enterscore.totgoals".$teamid.".value=total; 
} 
</script>
";
?>
</head>
<body>
<form name="enterscore">
<?
print 
"
<input type='text' name='$pstat' value='10' onChange = 'addscore".$teamid."(this)' onblur = 'submitForms".$teamid."(this)' MAXLENGTH='2' SIZE='2'>
<input type='text' name='$pstat' value='10' onChange = 'addscore".$teamid."(this)' onblur = 'submitForms".$teamid."(this)' MAXLENGTH='2' SIZE='2'>
<br /><br />
<input type='text' name='totgoals$teamid' value=''>
";
?>
</form>
</body>
</html>
 
that seems to do exactly what i need. i will plug that into our code and let ya know for sure.

thanks alot, i really really appreciate it.
i've given you all the reps i can for the time being, we need some rep loving from the heavy hitter guys. kynchief... hehe
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back