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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Total on blur

Status
Not open for further replies.

TheCandyman

Technical User
Sep 9, 2002
761
0
0
US
I'm trying to get a function to total amount values on blur of each input box. So it will total each value entered and then put the grand total in

Code:
function displ(cnt)
{
  Tot = document.form1.(Amount && cnt).value;
  alert(Tot);
  Tot = parseInt(document.form1.Amount.value) + parseInt(Tot);
  
  document.form1.Total.value = Tot ;
  return true;
}

Code:
                                 <tr> 
                                    <td align="right"><span class="count">1</span>
                                    					<input type="text" size="20" name="Name1" value=""/></td>
                                    <td>&nbsp;<input type="text" size="15" name="Title1" value=""/>
                                        &nbsp;<input type="text" size="15" name="Employer1" value=""/>
                                        &nbsp;<input type="text" size="5" name="Amount1" value="0" onblur="return displ(1);" /></td>
                                  </tr>     
                                   
                                 <tr> 
                                    <td align="right"><span class="count">2</span>

                                    					<input type="text" size="20" name="Name2" value=""/></td>
                                    <td>&nbsp;<input type="text" size="15" name="Title2" value=""/>
                                        &nbsp;<input type="text" size="15" name="Employer2" value=""/>
                                        &nbsp;<input type="text" size="5" name="Amount2" value="0" onblur="return displ(2);" /></td>
                                  </tr>     
                                   
                                 <tr> 
                                    <td align="right"><span class="count">3</span>
                                    					<input type="text" size="20" name="Name3" value=""/></td>
                                    <td>&nbsp;<input type="text" size="15" name="Title3" value=""/>

                                        &nbsp;<input type="text" size="15" name="Employer3" value=""/>
                                        &nbsp;<input type="text" size="5" name="Amount3" value="0" onblur="return displ(3);" /></td>
                                  </tr>
 
This:

Code:
document.form1.(Amount && cnt)

should probably be this:

Code:
document.form1.elements['Amount' + cnt]

- Where is the 'Amount' element or 'Total' element?

Code:
document.form1.Amount.value
...
document.form1.Total

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
BillyRayPreachersSon,

Your suggestion gave me an idea and i have a finished result, so i thought i should post this.

Code:
function displ()
{
	temp=cln(document.form1.Amount1.value);
	temp=temp + cln(document.form1.Amount2.value);
	temp=temp + cln(document.form1.Amount3.value);
	temp=temp + cln(document.form1.Amount4.value);
	temp=temp + cln(document.form1.Amount5.value);
  document.form1.Amount.value = temp ;
  return true;
}

function cln(str)
{
	re = /^\$|,/g;
	return parseInt(str.replace(re, ""));
}

Code:
<input type="text" size="5" name="Amount1" value="0" onblur="return displ();" />
...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top