www.webdeveloper.com
Results 1 to 7 of 7

Thread: Sum of form fields

Hybrid View

  1. #1
    Join Date
    Nov 2009
    Posts
    4

    Smile Sum of form fields

    Ok the code goes like this:

    // JavaScript Document
    function updatesum() {
    document.sumario.total.value = (document.sumario.precio[]1.value -0) + (document.sumario.precio[]2.value -0) + (document.sumario.precio[]3.value -0) + (document.sumario.precio[]4.value -0) + (document.sumario.precio[]5.value -0) + (document.sumario.precio[]6.value -0) + (document.sumario.precio[]7.value -0);

    I know that the problem here is the field name, but how do i make this work without having to change the names?

    I can't change them because i have many other functions with those names already.

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    document.sumario.elements['precio[]1'].value
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Nov 2009
    Posts
    4

    Question nop

    still not working look at the live form, here it is.

    http://www.foreverchef.com/test/forma.php

    and here's my sum code.

    http://www.foreverchef.com/test/autosum.js

  4. #4
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    updatesum does not have a closing bracket. Check the JavaScript Console.
    At least 98% of internet users' DNA is identical to that of chimpanzees

  5. #5
    Join Date
    Nov 2009
    Posts
    4

    Unhappy update

    I updated the code, but it still dosen't work, the field box dosent show the total.

    I also tried using (getElementsByName) and it didn't work either.

  6. #6
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    I can not see that updatesum is called anywhere?
    At least 98% of internet users' DNA is identical to that of chimpanzees

  7. #7
    Join Date
    Nov 2009
    Posts
    4

    great

    ok, great it works now! thanks.

    It's now printing in total (A), but now i need to do a couple other things.

    I want to print the same result to field (11)

    And i want to make a second sum for fields (1) to (10) and print them on field (12) and them sum (11) + (12) and print it on field (13).

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles