1. Calculate fields?!?

I'm trying to make this work, but something is not right?!

PHP Code:
``` <?php require_once('js/createturn_calc.php'); ?> <table width="100%" border="0" cellspacing="0" cellpadding="0">         <tr>           <td><div align="center"><input type="textbox" name="black_1" onblur="calc()" value="" class="scorecard"></div></td>         </tr>         <tr>           <td><div align="center"><input type="textbox" name="black_2" onblur="calc()" value="" class="scorecard"></div></td>         </tr>         <tr>           <td><div align="center"><input type="textbox" name="black_3" onblur="calc()" value="" class="scorecard"></div></td>         </tr>         <tr>           <td><div align="center"><input type="textbox" readonly name="black_total" class="scorecard" value=""></div></td>         </tr> </table> ```
createturn_calc.php:
Code JavaScript:
```<script type="text/javascript">
<!--

function calc(){
// Gathers field information

// BLACK
var b1 = validNum(document.scorecard.elements['black_1'].value);
var b2 = validNum(document.scorecard.elements['black_2'].value);
var b3 = validNum(document.scorecard.elements['black_3'].value);

// Calculates Information
var black = b1 + b2 + b3;

document.scorecard.elements['black_total'].value = black;

}

// Makes sure variable is a number
function validNum(nmbr){
// forces variable into integer type
nmbr = (nmbr * 1);

// Checks if variable is Not a Number
if(!isNaN(nmbr))
// If a number, return value
return nmbr;
else
// If not a number, return zero
return 0;
}
-->
</script>```

It gives an error return...

document.scorecard.elements is null or not a object...

Where do I go wrong?

2. JavaScript is not my strong point but I think that this:

document.scorecard.elements['black_total'].value = black;

Should really be this:

black = document.scorecard.elements['black_total'].value;

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•