HTML Tutorial


 Forum HomeForum Home   FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
RegisterRegister - Not registered yet? Got something to say? Join HTML Code Tutorial!
Summing values from table cells
Post new topic   Reply to topic    HTML Help Forum Index -> Javascript
View previous topic :: View next topic  
Author Message
qsiimn



Joined: 18 Dec 2007
Posts: 1

PostPosted: Tue Feb 26, 2008 3:03 pm     Summing values from table cells Reply with quote

I'm a first time poster in this forum.

I create very basic html forms for a work related function. Can someone get me started on a method for summing the input values from a table row? A very basic example might look like this:
<tr>
<td>Input 1<input type="text" name="input1"></td>
<td>Input 2<input type="text" name="input2"></td>
<td>Sum <???></td>
Is there a simple javascript that will do this?


[/code]
kanenas



Joined: 14 Dec 2004
Posts: 191

PostPosted: Sun Mar 16, 2008 2:12 am     javascript & forms Reply with quote

First thing, get rid of that table stuff. The only thing that should go in tables is tabular data (why? there are quite a few pages that state why).

Second thing to know: how to access the form in javascript. You can access all the forms in a document in javascript via 'document.forms', which is indexed both by number and form name. You can access a form from within the event handler for an input element via 'this.form'. Example:
Code:
<form name="increment">
<button onclick="this.form.out.value=parseInt(this.form.out.value)+1">Increment</button>
<input name="out" value="0">
</form>
<script type="text/javascript">
/* both of the following access the value of the "out" input,
assuming "increment" is the first form in this document
*/
document.forms.increment.out.value;
document.forms[0].out.value;
</script>

Notice input elements are accessed using their name as a property of their parent (the text input with name "out" is accessed via "this.form.out"). To get at the value, you need to access the "value" property of the input element (e.g. "this.form.out.value").

That may not seem clear now, but if you read through the form tutorial on this very site and the quirksmode page on form validation (the information will help you handle forms with javascript).

Hopefully that's enough of a lead that you can get started and ask questions down the line if you get stuck.
Display posts from previous:   
Post new topic   Reply to topic    HTML Help Forum Index -> Javascript All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
HTML Help Archive
Powered by phpBB © 2001, 2005 phpBB Group
 
HOSTING / DESIGN
MAKE MONEY

Home
  |   Tutorials   |   Forum   |   Quick List   |   About
Copyright ©1997-2002 Idocs and ©2002-2007 HTML Code Tutorial