Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding numbers in cells

Status
Not open for further replies.

schoch

Technical User
Jan 17, 2007
13
AU
I usually work in php and was told I could not add cells to total automatically.
I need help with javascript as I now nothing. I hope this makes sense!


I want to tally up the numbers inputted in each cell for the specific column e.g.
CODE
<input name="md1" type="text" id="md1" size="10" />
and
<input name="md2" type="text" id="md1" size="10" />
=<input name="md_total" type="text" id="md_total" size="10" value="<?php
$md1=md1;
$md2=md2;
$md_total=($md1+$md2);

echo $md_total;
?>"/>
How do I do it so it automatically adds without having to use a submit button??
 
Bare minimal.

[tt]<input name="md1" type="text" id="md1" size="10" [blue]onblur="this.form.md_total.value=parseInt(this.form.md1.value,10)+parseInt(this.form.md2.value,10);"[/blue] />
and
<input name="md2" type="text" id="md[red]2[/red]" size="10" onblur="this.form.md_total.value=parseInt(this.form.md1.value,10)+parseInt(this.form.md2.value,10);" /> [red]<!-- avoid id collision as much as you can -->[/red]
=<input name="md_total" type="text" id="md_total" size="10" [blue]readonly="readonly"[/blue] />
[/tt]
But if you know nothing about client-side scripting, even this simple thing may become enough complicate in order to avoid some unplesant features of such a minimal approach.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top