form value addition

S

simon.croome

Hi,

I am trying to create a function that will add values from several
form select boxes and output the result to another textfield.

my code is below, but I cannot get it to work.

Can anyone help ? Thanks.

function calcform(form) {

document.frmstorage.txttotufs.value =
number(+document.frmstorage.lstdiskspd1.value) +
number(+document.frmstorage.lstdiskspd2.value) +
number(+document.frmstorage.lstdiskspd3.value) +

number(+document.frmstorage.lstdiskspd4.value) +
number(+document.frmstorage.lstdiskspd5.value) +

number(+document.frmstorage.lstdiskspd6.value) +
number(+document.frmstorage.lstdiskspd7.value) +
number(+document.frmstorage.lstdiskspd8.value)
}

</script>
 
L

Lee

(e-mail address removed) said:
Hi,

I am trying to create a function that will add values from several
form select boxes and output the result to another textfield.

my code is below, but I cannot get it to work.

Can anyone help ? Thanks.

Have you read the material assigned by your instructor?


--
 
T

Thomas 'PointedEars' Lahn

I am trying to create a function that will add values from several
form select boxes and output the result to another textfield.

my code is below, but I cannot get it to work.

Some people say debugging would help ...

http://jibbering.com/faq/
Can anyone help ? Thanks.

function calcform(form) {

document.frmstorage.txttotufs.value =
number(+document.frmstorage.lstdiskspd1.value) +
number(+document.frmstorage.lstdiskspd2.value) +

You must be kidding. For goodness sake, use two or four *space* characters
for indentation instead. *At least* for posting.

[Tab characters replaced by spaces]
number(+document.frmstorage.lstdiskspd3.value) [...]

You have not posted the code of the number() method (and probably you
meant `Number' -- ECMAScript identifiers are case-sensitive), but it
is very likely/for sure that calling it is not necessary as the unary
`+' operator already performs the conversion to the Number type.

Your referencing can be improved, too. Given that you already pass a
reference to the corresponding HTMLFormElement object with `form' (you
have not posted the method call either), the following would suffice:

var es = form.elements;
es["txttotufs"].value =
+es["lstdiskspd3"].value
// ...

That is not only standards-compliant and backwards-compatible, and easier
to maintain, but also much more runtime-efficient.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,156
Messages
2,570,878
Members
47,404
Latest member
PerryRutt

Latest Threads

Top