multiple form field calculation

This is a discussion on "multiple form field calculation" within the JavaScript Forum section. This forum, and the thread "multiple form field calculation are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Feb 21st, 2008, 05:55
New Member
Join Date: Jan 2008
Location: sydney
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
multiple form field calculation

Hi guys,

I'm still very new to the world of javascript and I am trying to make a script that will calculate up to 10 form fields in 1 loop.

can anyone point me to a tutorial on adding multiple form fields or can provide me with a little snippet it would be greatly appreciated.

thanks
Reply With Quote

  #2 (permalink)  
Old Feb 21st, 2008, 09:00
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: multiple form field calculation

To get 10 form fields a simply way of doing it is giving your form a unique id -- let's say id="theform"

You would then do this

Code: Select all
var formInputs = document.getElementById('theForm').getElementsByTagName('input');

// now loop through

var nm = formInputs.length; // get the number of inputs

var runningTotal = 0; // This will store the total in the inputs
for (i=0; i< nm; i++)
{
    runningTotal += formInputs[i].value;
}

document.write(runningTotal);
You can get a bit more specific with how you address the inputs but that is nice solid start.
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #3 (permalink)  
Old Feb 21st, 2008, 22:32
CloudedVision's Avatar
Nerdy Moderator
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 942
Blog Entries: 8
Thanks: 2
Thanked 22 Times in 22 Posts
Send a message via AIM to CloudedVision Send a message via MSN to CloudedVision Send a message via Skype™ to CloudedVision
Re: multiple form field calculation

i wouldn't rely on javascript..... i would go the server-side route and have PHP (or ASP or somethin) generate it.

Never use javascript if you don't have to.
__________________
echo "Take it easy, ".$CloudedVision;
.links { site: other-road-design; blog: only-nerds-allowed; project: resource-fish; organization: ARMIES6; }
<quote>&quot;I think it's wrong that only one company makes the game Monopoly&quot; - <name>Steven Wright</name></quote>
Last Blog Entry: More Cheat Sheets (Jul 12th, 2008)
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Form with confirm password field dhossai JavaScript Forum 28 Dec 16th, 2007 05:12
Working with Form 'file field' data in ASP. daryl Classic ASP 3 Jun 24th, 2006 20:22
Number validation in form field Matc JavaScript Forum 2 May 26th, 2006 15:05
Newbie: changing the value of a field on form d9085 Databases 1 Dec 12th, 2005 18:08
Add a form field csa Web Page Design 8 Nov 23rd, 2005 20:33


All times are GMT. The time now is 19:40.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43