Yes; it is (at least) the following:
1. Your referencing is proprietary, at best error-prone, needlessly.
stanForm.VD.value
is not appropriate referencing (throw that book away). Assuming that
your control is descendant of a form element named `stanForm' (which you
have not showed), an appropriate, standards-compliant, backwards
compatible and less error-prone referencing would be
document.forms['stanForm'].elements['VD'].value
However, as that code appears to be part of the event-handler attribute
value of the very element that is represented by
document.forms['stanForm'].elements['VD']
you can replace that with
this
so that the element reads
<input type="text" name="VD" size="7"
onchange="save(this.value, AInput, 'Valve Diameter')">
2. You are referring to an identifier before you declare or define it.
`AInput' is neither declared nor defined before save() is called, so for
all we know,
save(this.value, AInput, 'Valve Diameter')
throws a ReferenceError when evaluating `AInput'. Check your error
console.
It is possible that you have
var AInput;
somewhere in your code, or even
<form name="stanForm" …>
…
<input name="AInput" …>
…
</form>
(see also <
http://stackoverflow.com/questions/9158238/why-js-function-
name-conflicts-with-element-id/9160009#9160009>), but then you should
have posted that.
3. You are using eval().
Given the aforementioned `forms' and `elements' collections, you do not
have to use eval() here. See also <
http://jibbering.com/faq/#eval> (in
general, *always* read the FAQ of the newsgroup(s) *before* you post to
them).
4. You are using eval() wrong.
You are passing for the argument of eval() – `field' – the value of the
control that calls the very same function. One could surmise from this
that you might be trying to implement a calculator.
However, this assumption contradicts your programming where you
explicitly do not enter the branch with the eval() calls when the string
value cannot be interpreted as a number, such as a non-trivial equation
(operand operator operand).
It is also rather far-fetched to assume that your user would enter
the names of controls in your form in that input control.
Therefore, your calls to eval() appear to be completely pointless. To
convert a string value to a number value, use the unary `+' operator,
or the parseInt(…, radix) or parseFloat(…) function calls.
5. "Does not work" is not a problem description. Read the FAQ on how to
post when you desire useful answers.
6. You can assign to a function argument, but that does not change the
value passed for that argument. There is no call-by-reference, all
function arguments are values. (But it does not appear as if you were
trying to use the assumed assigned value anywhere, so this appears
to be pointless anyway.)
7. The `change' event occurs on the control when the control loses focus,
not before. Do not have your users rely on that, provide a button for
the computation. You may perform form validation on change, but you
should do it in a non-obtrusive way (like adding color).
Perform any validation that hinders or blocks the user's workflow (like
an alert message) only on submit; the `form' element has an `onsubmit'
event-handler attribute for that.
8. Avoid the window.alert() method. In particular, in recent Gecko-based
browsers, such an alert message disables the entire viewport of a tab
until the message is dismissed, and it is very likely to cover the parts
where the error is. (IMHO yet another incredibly bad design decision
in Geckos that we now need to work around – thanks guys :->)
9. Is your markup Valid? Declare HTML 4.01 Strict or (if necessary) HTML5,
and replace presentational attributes (like `align') and elements with
CSS. <
http://validator.w3.org/>
Bottom line: Learn the markup and programming languages before you use an
API with the programming language, and try something much more simple than
this first.
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee