{"id":18045401,"url":"https://github.com/lance/formtotal","last_synced_at":"2025-08-16T19:12:35.753Z","repository":{"id":500443,"uuid":"127468","full_name":"lance/formtotal","owner":"lance","description":"A simple javascript class that dynamically adds up the values of form fields and updates a \"total\" field.","archived":false,"fork":false,"pushed_at":"2009-02-15T13:29:46.000Z","size":132,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-05T03:41:53.870Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lance.png","metadata":{"files":{"readme":"README.textile","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2009-02-12T15:35:18.000Z","updated_at":"2019-08-13T14:00:25.000Z","dependencies_parsed_at":"2022-07-20T19:19:17.709Z","dependency_job_id":null,"html_url":"https://github.com/lance/formtotal","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lance/formtotal","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lance%2Fformtotal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lance%2Fformtotal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lance%2Fformtotal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lance%2Fformtotal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lance","download_url":"https://codeload.github.com/lance/formtotal/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lance%2Fformtotal/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270758528,"owners_count":24640257,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-16T02:00:11.002Z","response_time":91,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-30T18:13:04.570Z","updated_at":"2025-08-16T19:12:35.724Z","avatar_url":"https://github.com/lance.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"h1. formtotal\n\nThis is a simple javascript class that will add up input fields \nwith a class of @addend@ in a form and place the running total\nin an input field with an ID of @total@ and ensure that field is\ndisabled.\n\nEach time the @total@ field is updated, a cookie is set in the\nbrowser to maintain the total value.  Any form field with the ID\nof @total@ will be prepopulated with the value of this cookie.\n\nh2. Usage\n\nThis code relies on Mootools.  It has been tested and ships with version 1.2.1.  Add the following lines to the @\u003chead\u003e@ element of your HTML document.\n  \n@\u003cscript type=\"text/javascript\" src=\"scripts/mootools.js\" charset=\"utf-8\"\u003e\u003c/script\u003e@\n\n@\u003cscript type=\"text/javascript\" src=\"scripts/formtotal.js\" charset=\"utf-8\"\u003e\u003c/script\u003e@\n\nAdd the @addend@ class to all form elements to be included in the running total.\nSet the @id@ of the field containing the total amount to @total@.  Serve chilled.\n\nh2. Customization\n\nThe Summarizer class just takes an array of DOM elements.  When the page loads, the code waits for the DOM to be ready, gets all of the elements to be summarized, and passes those into the Summarizer constructor.  It looks like this:\n\n\u003cpre\u003e\u003ccode\u003e\n  window.addEvent('domready', function initialize() {\n  \tsummary_fields = document.getElementsByClassName(addendClassName);\n  \tnew Summarizer(summary_fields, totalFieldID, cookieName);\n  });\n\u003c/code\u003e\u003c/pre\u003e\n\nIt's just getting the list of all DOM elements for a given class and passing those to the Summarizer constructor.  So, to customize the script to use IDs, you'd change it to look something like this (this works with the sample form):\n\n\u003cpre\u003e\u003ccode\u003e\n  window.addEvent('domready', function initialize() {\n  \tvar summary_fields = [];\n  \tfor(var i=1; i\u003c6; i++) {\n  \t\telementID = \"invoice_amount_\" + i;  // Change this line to specify what the ID is for the elements you want \n  \t\tif ($(elementID)) {\n  \t\t\tsummary_fields.push($(elementID));\n  \t\t}\n  \t}\n  \tnew Summarizer(summary_fields, totalFieldID, cookieName);\n  });\n\u003c/code\u003e\u003c/pre\u003e\n\nOr just manually create an array of elements you want to summarize, e.g.:\n\n\u003cpre\u003e\u003ccode\u003e\n  window.addEvent('domready', function initialize() {\n  \tvar summary_fields = [$('item1'), $('item2'), $('item3')];\n  \tnew Summarizer(summary_fields, totalFieldID, cookieName);\n  });\n\u003c/code\u003e\u003c/pre\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flance%2Fformtotal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flance%2Fformtotal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flance%2Fformtotal/lists"}