<andyhajime@dsdexigns.comwrites:
Quote:
The problem lies here eval("document.TeeForm.amt.value(S+M)");
Much of the problem lies here.
Quote:
S and M suppose to add up and the total suppose to appear on the AMT field
but it didn't.
Then what happened? Did you get an error? (Are error reports turned on
in your browser?) Was something wrong put in the field?
I'll start from the top :)
Quote:
<FORM NAME="TeeForm">
I recommend adding an "id" attribute too, which is really the correct
thing to do, and the "name" attribute is only for backwards
compatability:
<form id="TeeForm" name="TeeForm">
Quote:
<INPUT TYPE="button" VALUE=" s1 " OnClick="TeeForm.Small.value =
'1';javascript
:STotal();">
The "javascript
:" is superflous in the onclick attribute. I recommend
changing this onclick attribute to something like:
onclick="this.form.elements['Small'].value='1'; sumTotal(this.form);"
I added a reference to the form as an argument to sumTotal function
so that the function has easier access to the form. I'll change the
function below to match this.
(I renamed STotal since tradition has javascript function names
starting with lower case letters)
Generally, you don't want to write "javascript
:". It's not necessary
in event handlers (like onclick), and it's a very bad idea in links.
If you see "javascript
:", then assume something needs to be fixed.
Quote:
<script language="JavaScript">
Should be:
<script type="text/javascript">
The "type" attribute is required for valid HTML, and is always sufficient.
Quote:
function STotal()
{
var S = document.TeeForm.Small.value
I recommend accessing forms and form controls using the document.forms
and form.elements collections. It's not always necessary, but it *always*
works.
var s = document.forms['TeeForm'].elements['Small'].value;
However, if you have the form as a parameter of the function, you
can start from there instead of looking up the form every time
you need it.
Quote:
var M = document.TeeForm.Medium.value
eval("document.TeeForm.amt.value(S+M)");
There is absolutely no need for "eval" here. Generally, there is no
need for eval, and any occurence of it should be considered a warning
sign that the author is not entirely sure what he's doing.
In this case,
eval("document.TeeForm.amt.value(S+M)");
is completely equivalent to:
document.TeeForm.amt.value(S+M);
which doesn't work for two reasons.
First, S+M is performing string concatenation, since S and M are string
values (all input control values are). You should convert these to numbers
before adding them, e.g.:
Number(S)+Number(M)
Second, it is treating the value of the "amt" control as a function. As
just stated, it is a string, so that won't work. You'll want to assign
to the value property instead.
Here's a suggestion for a revised sum function:
function sumTotal(form) {
var s = form.elements['Small'].value;
var m = form.elements['Medium'].value;
var sum = Number(s) + Number(m);
form.elements['amt'].value = sum;
}
Good luck
/L
--
Lasse Reichstein Nielsen -
lrn@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'