IT Community - Software Programming, Web Development and Technical Support

How can I add up the values in several text fields and place the result in another te

This is a discussion on How can I add up the values in several text fields and place the result in another te within the HTML, CSS and Javascript Coding Techniques forums, part of the Web Development category; How can I add up the values in several text fields and place the result in another text field?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > HTML, CSS and Javascript Coding Techniques

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 03-22-2008, 02:04 AM
GDevakii GDevakii is offline
D-Web Sr.Programmer
 
Join Date: Aug 2007
Posts: 138
GDevakii is on a distinguished road
Question How can I add up the values in several text fields and place the result in another te

How can I add up the values in several text fields and place the result in another text field?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-22-2008, 02:05 AM
GDevakii GDevakii is offline
D-Web Sr.Programmer
 
Join Date: Aug 2007
Posts: 138
GDevakii is on a distinguished road
Smile Re: How can I add up the values in several text fields and place the result in anothe

<script language="JavaScript"><!--
function calculate(what) {
for (var i=1,answer=0;i<9;i++)
answer += what.elements['textField' + i].value - 0;
what.answer.value = answer;
}
//--></script>

<form>
<input type="text" name="textField1"><br>
<input type="text" name="textField2"><br>
<input type="text" name="textField3"><br>
<input type="text" name="textField4"><br>
<input type="text" name="textField5"><br>
<input type="text" name="textField6"><br>
<input type="text" name="textField7"><br>
<input type="text" name="textField8"><br>
<input type="text" name="answer">
<input type="button" value="Calcuate" onClick="calculate(this.form)">
</form>
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-22-2008, 02:05 AM
GDevakii GDevakii is offline
D-Web Sr.Programmer
 
Join Date: Aug 2007
Posts: 138
GDevakii is on a distinguished road
Default How can I sum the prices and quantities of many different form fields to produce a to

How can I sum the prices and quantities of many different form fields to produce a total price?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-22-2008, 02:06 AM
GDevakii GDevakii is offline
D-Web Sr.Programmer
 
Join Date: Aug 2007
Posts: 138
GDevakii is on a distinguished road
Smile Re: How can I add up the values in several text fields and place the result in anothe

<SCRIPT LANGUAGE="JavaScript"><!--
function cent(amount) {
return (amount == Math.floor(amount)) ? amount + '.00' : ( (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
}

function total(what,number) {
var grandTotal = 0;
for (var i=0;i<number;i++) {
if (what.elements['price' + i].value == '')
what.elements['price' + i].value == '0.00'; // fix for Opera.
grandTotal += (what.elements['price' + i].value - 0) * (what.elements['quantity' + i].value - 0);
}
what.grandTotal.value = cent(Math.round(grandTotal*Math.pow(10,2))/Math.pow(10,2));
}
//--></SCRIPT>

<FORM NAME="myName">
Quantity: <INPUT TYPE="text" NAME="quantity0" SIZE="3"> Price: <input TYPE="text" NAME="price0" VALUE="0.99" SIZE="4"><BR>
Quantity: <INPUT TYPE="text" NAME="quantity1" SIZE="3"> Price: <input TYPE="text" NAME="price1" VALUE="1.99" SIZE="4"><BR>
Quantity: <INPUT TYPE="text" NAME="quantity2" SIZE="3"> Price: <input TYPE="text" NAME="price2" VALUE="2.99" SIZE="4"><BR>
Quantity: <INPUT TYPE="text" NAME="quantity3" SIZE="3"> Price: <input TYPE="text" NAME="price3" VALUE="3.99" SIZE="4"><BR>
Quantity: <INPUT TYPE="text" NAME="quantity4" SIZE="3"> Price: <input TYPE="text" NAME="price4" VALUE="4.99" SIZE="4"><BR>
Quantity: <INPUT TYPE="text" NAME="quantity5" SIZE="3"> Price: <input TYPE="text" NAME="price5" VALUE="5.99" SIZE="4"><BR>
Quantity: <INPUT TYPE="text" NAME="quantity6" SIZE="3"> Price: <input TYPE="text" NAME="price6" VALUE="6.99" SIZE="4"><BR>
Quantity: <INPUT TYPE="text" NAME="quantity7" SIZE="3"> Price: <input TYPE="text" NAME="price7" VALUE="7.99" SIZE="4"><BR>
Quantity: <INPUT TYPE="text" NAME="quantity8" SIZE="3"> Price: <input TYPE="text" NAME="price8" VALUE="8.99" SIZE="4"><BR>
Quantity: <INPUT TYPE="text" NAME="quantity9" SIZE="3"> Price: <input TYPE="text" NAME="price9" VALUE="9.99" SIZE="4"><BR>
<INPUT TYPE="button" VALUE="Total" onClick="total(this.form,10)"> Grand Total: <INPUT TYPE="TEXT" NAME="grandTotal" SIZE="6">
</FORM>
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-22-2008, 02:06 AM
GDevakii GDevakii is offline
D-Web Sr.Programmer
 
Join Date: Aug 2007
Posts: 138
GDevakii is on a distinguished road
Question How do I automatically submit a form after a timer function expires?

How do I automatically submit a form after a timer function expires?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 03-22-2008, 02:07 AM
GDevakii GDevakii is offline
D-Web Sr.Programmer
 
Join Date: Aug 2007
Posts: 138
GDevakii is on a distinguished road
Smile Re: How can I add up the values in several text fields and place the result in anothe

<FORM NAME="myForm">
</FORM>

<SCRIPT LANGUAGE="JavaScript"><!--
setTimeout('document.myForm.submit()',5000);
//--></SCRIPT>
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 03-22-2008, 02:07 AM
GDevakii GDevakii is offline
D-Web Sr.Programmer
 
Join Date: Aug 2007
Posts: 138
GDevakii is on a distinguished road
Question Can I pass JavaScript variables to a CGI Perl program?

Can I pass JavaScript variables to a CGI Perl program?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 03-22-2008, 02:08 AM
GDevakii GDevakii is offline
D-Web Sr.Programmer
 
Join Date: Aug 2007
Posts: 138
GDevakii is on a distinguished road
Smile Re: How can I add up the values in several text fields and place the result in anothe

<html>
<head>
<script language="javascript">
function Sendvalues() {
var firstname = 'Jason'; // JavaScript variable containing firstname
document.forms('cgivalues').firstname.value=firstn ame;
document.forms('cgivalues').submit();
}

</head>
<body>

<form name="cgivalues" action="POST" action="script.pl">
<input type="hidden" name="firstname">
</form>

</body>
</html>

var firstname = 'Jason'; // JavaScript variable containing firstname

document.write('<form name="cgivalues" action="POST" action="script.pl">';
document.write('<input type="hidden" name="firstname" value="'+firstname+'">';
document.write('</form>');

document.forms('cgivalues').submit();
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 03-22-2008, 02:09 AM
GDevakii GDevakii is offline
D-Web Sr.Programmer
 
Join Date: Aug 2007
Posts: 138
GDevakii is on a distinguished road
Question How do I target differrent frames based on a URL value selected from a drop down list

How do I target differrent frames based on a URL value selected from a drop down list?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 03-22-2008, 02:09 AM
GDevakii GDevakii is offline
D-Web Sr.Programmer
 
Join Date: Aug 2007
Posts: 138
GDevakii is on a distinguished road
Smile Re: How can I add up the values in several text fields and place the result in anothe

<SCRIPT LANGUAGE="JavaScript"><!--
function go(what) {
value = what.options[what.selectedIndex].value;
if (value == '') return;
if (value.indexOf('http://') == 0)
parent.frames[0].location.href = value;
else
parent.frames[1].location.href = value;
}
//--></SCRIPT>

<FORM>
<SELECT onChange="go(this)">
<OPTION VALUE="">Select one:
<OPTION VALUE="http://www.irt.org/index.htm">irt.org
<OPTION VALUE="index.htm">Index
</SELECT>
</FORM>
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #11 (permalink)  
Old 11-14-2008, 05:04 AM
levelup2 levelup2 is offline
D-Web Trainee
 
Join Date: Nov 2008
Posts: 8
levelup2 is on a distinguished road
Default Re: How can I add up the values in several text fields and place the result in anothe

Thanks for all your post
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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

vB 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
is possible to extract the values in the below fields?.. kingmaker C# Programming 1 02-27-2008 09:53 PM
How do I use my own graphic button to reset all the text fields in a form? Pvinothkumar HTML, CSS and Javascript Coding Techniques 1 11-02-2007 12:02 AM
How do I check that text entered in a text form field is an integer? itbarota HTML, CSS and Javascript Coding Techniques 2 10-26-2007 12:25 AM
Info on Supplement Result vadivelanvaidyanathan Google 0 05-22-2007 02:56 AM
Any tool to get the Search Engine result montyauto Search Engine Optimization 4 04-23-2007 12:10 AM


All times are GMT -7. The time now is 11:15 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0