Advertisement

07.05.2008 at 12:53PM PDT, ID: 23540968
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

Javascript add one and subtract one buttons for an online calculator

Asked by hellenica in JavaScript, Hypertext Markup Language (HTML), PHP Scripting Language

Tags:

I am developing this online calculator and i decided to try to put in two auto populate buttons:

1. and "add one unit" button
2. and a "subtract one unit" button.

I have a rough sketch of what I want to accomplish here:

http://vig.com.cy/demo/money.html

I began by using a script I found online, made some modifications, and now the script I am using looks like the one in the attached code snippet.

As you can understand, what I really want to do is that I press on the + or - button, and it auto populates the yellow quantity fields on the left.

Can you guide me?

-Hellenica

Start Free Trial
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:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
<HTML>
<HEAD>
<TITLE>Calculating Order Form Totals in  JavaScript</TITLE>
<META NAME="AUTHOR" CONTENT="Paul McFedries">
<META HTTP-EQUIV="Description" NAME="Description" CONTENT="A JavaScript routine that calculates a running total for an order form"
<META HTTP-EQUIV="Keywords" NAME="Keywords" CONTENT="Paul McFedries, JavaScript, order form, total, calculation">
 
<style type="text/css">
<!--
.style1 {font-size: 24px}
-->
</style>
</HEAD>
 
<LINK REL="stylesheet" TYPE="text/css" HREF="/stylesheet.css">
 
<script language="JavaScript" type="text/javascript">
<!--
 
/* This script is Copyright (c) Paul McFedries and 
Logophilia Limited (http://www.mcfedries.com/).
Permission is granted to use this script as long as 
this Copyright notice remains in place.*/
 
function CalculateTotal(frm) {
    var order_total = 0
 
    // Run through all the form fields
    for (var i=0; i < frm.elements.length; ++i) {
 
        // Get the current field
        form_field = frm.elements[i]
 
        // Get the field's name
        form_name = form_field.name
 
        // Is it a "product" field?
        if (form_name.substring(0,4) == "PROD") {
 
            // If so, extract the price from the name
            item_price = parseFloat(form_name.substring(form_name.lastIndexOf("_") + 1))
 
            // Get the quantity
            item_quantity = parseInt(form_field.value)
 
            // Update the order total
            if (item_quantity >= 0) {
                order_total += item_quantity * item_price
            }
        }
    }
 
    // Display the total rounded to two decimal places
    frm.TOTAL.value = round_decimals(order_total, 2)
}
 
function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}
 
function pad_with_zeros(rounded_value, decimal_places) {
 
    // Convert the number to a string
    var value_string = rounded_value.toString()
    
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")
 
    // Is there a decimal point?
    if (decimal_location == -1) {
        
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
        
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {
 
        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length
    
    if (pad_total > 0) {
        
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}
 
 
//-->
</script>
 
<BODY MARGINWIDTH=0 MARGINHEIGHT=0 LEFTMARGIN=0 TOPMARGIN=0 BGCOLOR=#FFFFFF>
 
 
<A NAME="top"></A>
 
<!--START THE HEADER-->
<!--END THE HEADER-->
<!--START THE CONTENT-->
<DIV STYLE="margin-left: 5px; font-family: Arial, Verdana, Helvetica, Geneva, 'MS Sans Serif'">
<CENTER>
<TABLE WIDTH=100% CELLSPACING=0 CELLPADDING=0>
  <TR><TD><IMG SRC="/Graphics/spacer.gif" HEIGHT=1 WIDTH=610><BR>
 
<FONT FACE="Arial, Verdana, Helvetica, MS Sans Serif" COLOR=#000088 SIZE=+2 CLASS="TitleText">
<B>Village Internet &amp; Gaming Calculator </B></FONT>
<P>
 
<HR>
<P>
 
<FORM>
 
<H3>SIMPLE TOOL TO CALCULATE TOTALS </H3>
 
 
<TABLE width="75%" BORDER =3 align="center" cellpadding="5" cellspacing="2">
 
  <TD COLSPAN=5><B>Enter quantities to the right by clicking the appropriate button... </B></TD>
 
<TR>
<TD width="16%" ALIGN="CENTER">Quantity:</TD>
 
<TD width="40%" ALIGN="center" valign="middle"><B>Description</TD>
<TD width="15%" ALIGN="CENTER"><B>Price<BR>
(each)</B></TD>
<TD width="15%" ALIGN="CENTER">Add <br>
  Unit </TD>
<TD width="14%" ALIGN="CENTER">Subtract <br>
  Unit </TD>
</TR>
<TR>
<TD ALIGN="CENTER"><INPUT TYPE=TEXT  readonly style="background-color:#ffffc6" NAME="PROD_SP_0.65" SIZE=5 MAXLENGTH=5 onChange="CalculateTotal(this.form)"></TD>
<TD align="center" valign="middle"><span class="style1">Soft Drink </span></TD>
<TD ALIGN="center" valign="middle"><span class="style1">0.65  &euro;</span></TD>
<TD ALIGN="center" valign="middle"><p><img src="img/plus.gif" width="59" height="62"></p>  </TD>
<TD ALIGN="center" valign="middle"><img src="img/minus.gif" width="61" height="62"></TD>
</TR>
<TR><TD ALIGN="CENTER"><INPUT TYPE=TEXT readonly style="background-color:#ffffc6" NAME="PROD_SPMG_0.50" SIZE=5 MAXLENGTH=5 onChange="CalculateTotal(this.form)"></TD>
<TD align="center" valign="middle"><span class="style1">Water</span></TD>
<TD ALIGN="center" valign="middle"><span class="style1">0.50  &euro;</span></TD>
  <TD ALIGN="center" valign="middle"><p><img src="img/plus.gif" width="59" height="62"></p>    </TD>
  <TD ALIGN="center" valign="middle"><img src="img/minus.gif" width="61" height="62"></TD>
</TR>
<TR><TD ALIGN="CENTER"><INPUT TYPE=TEXT readonly style="background-color:#ffffc6" NAME="PROD_SPCR_0.65" SIZE=5 MAXLENGTH=5 onChange="CalculateTotal(this.form)"></TD>
<TD align="center" valign="middle"><span class="style1">Snacks</span></TD>
<TD ALIGN="center" valign="middle"><span class="style1">0.65  &euro;</span></TD>
 
  <TD ALIGN="center" valign="middle"><p><img src="img/plus.gif" width="59" height="62"></p>    </TD>
  <TD ALIGN="center" valign="middle"><img src="img/minus.gif" width="61" height="62"></TD>
</TR>
<TR><TD ALIGN="CENTER"><INPUT TYPE=TEXT  readonly style="background-color:#ffffc6" NAME="PROD_SW_1.25" SIZE=5 MAXLENGTH=5 onChange="CalculateTotal(this.form)"></TD>
<TD align="center" valign="middle"><span class="style1">Sandwich</span></TD>
<TD ALIGN="center" valign="middle"><span class="style1">1.25  &euro;</span></TD>
  <TD ALIGN="center" valign="middle"><p><img src="img/plus.gif" width="59" height="62"></p></TD>
  <TD ALIGN="center" valign="middle"><img src="img/minus.gif" width="61" height="62"></TD>
</TR>
<TR><TD ALIGN="CENTER"><INPUT TYPE=TEXT  readonly style="background-color:#ffffc6" NAME="PROD_SWMG_1.00" SIZE=5 MAXLENGTH=5 onChange="CalculateTotal(this.form)"></TD>
<TD align="center" valign="middle"><span class="style1">1/2 hour computer </span></TD>
<TD ALIGN="center" valign="middle"><span class="style1">1.00  &euro;</span></TD>
  <TD ALIGN="center" valign="middle"><p><img src="img/plus.gif" width="59" height="62"></p>    </TD>
  <TD ALIGN="center" valign="middle"><img src="img/minus.gif" width="61" height="62"></TD>
</TR>
<TR><TD ALIGN="CENTER"><INPUT TYPE=TEXT  readonly style="background-color:#ffffc6" NAME="PROD_RY_2.00" SIZE=5 MAXLENGTH=5 onChange="CalculateTotal(this.form)"></TD>
<TD align="center" valign="middle"><span class="style1">1 hour computer </span></TD>
<TD ALIGN="center" valign="middle"><span class="style1">2.00  &euro;</span></TD>
  <TD ALIGN="center" valign="middle"><p><img src="img/plus.gif" width="59" height="62"></p>    </TD>
  <TD ALIGN="center" valign="middle"><img src="img/minus.gif" width="61" height="62"></TD>
</TR>
<TR><TD ALIGN="CENTER"><INPUT TYPE=TEXT  readonly style="background-color:#ffffc6" NAME="PROD_KT_10.00" SIZE=5 MAXLENGTH=5 onChange="CalculateTotal(this.form)"></TD>
<TD align="center" valign="middle"><span class="style1">8.5 hour computer </span></TD>
<TD ALIGN="center" valign="middle"><span class="style1">10.00  &euro;</span></TD>
 
  <TD ALIGN="center" valign="middle"><p><img src="img/plus.gif" width="59" height="62"></p></TD>
  <TD ALIGN="center" valign="middle"><img src="img/minus.gif" width="61" height="62"></TD>
</TR>
<TR><TD ALIGN="CENTER"><INPUT TYPE=TEXT  readonly style="background-color:#ffffc6" NAME="PROD_KCR_20.00" SIZE=5 MAXLENGTH=5 onChange="CalculateTotal(this.form)"></TD>
<TD align="center" valign="middle"><span class="style1">1 week pass <br>
  *Internet Only* </span></TD>
<TD ALIGN="center" valign="middle"><span class="style1">20.00  &euro;</span></TD>
  <TD ALIGN="center" valign="middle"><p><img src="img/plus.gif" width="59" height="62"></p></TD>
  <TD ALIGN="center" valign="middle"><img src="img/minus.gif" width="61" height="62"></TD>
</TR>
<TR><TD ALIGN="CENTER"><INPUT TYPE=TEXT  readonly style="background-color:#ffffc6" NAME="PROD_KA_17.00" SIZE=5 MAXLENGTH=5 onChange="CalculateTotal(this.form)"></TD>
<TD align="center" valign="middle"><span class="style1">1 week pass <br>
  *WoW Club Only* </span></TD>
<TD ALIGN="center" valign="middle"><span class="style1">17.00  &euro;</span></TD>
  <TD ALIGN="center" valign="middle"><p><img src="img/plus.gif" width="59" height="62"></p></TD>
  <TD ALIGN="center" valign="middle"><img src="img/minus.gif" width="61" height="62"></TD>
</TR>
<TR><TD ALIGN="CENTER"><INPUT TYPE=TEXT  readonly style="background-color:#ffffc6" NAME="PROD_AG_25.00" SIZE=5 MAXLENGTH=5 onChange="CalculateTotal(this.form)"></TD>
<TD align="center" valign="middle"><span class="style1">Something else... </span></TD>
<TD ALIGN="center" valign="middle"><span class="style1">25.00  &euro;</span></TD>
  <TD ALIGN="center" valign="middle"><img src="img/plus.gif" width="59" height="62"></TD>
  <TD ALIGN="center" valign="middle"><img src="img/minus.gif" width="61" height="62"></TD>
<TR><TD><BR></TD><TD>TOTAL</TD><TD ALIGN="RIGHT"><INPUT TYPE=TEXT NAME=TOTAL SIZE=10 onFocus="this.form.elements[0].focus()">    
     &euro;</TD>
 
  <TD ALIGN="RIGHT">&nbsp;</TD>
  <TD ALIGN="RIGHT">&nbsp;</TD>
</TABLE>
 
<P>
 
<INPUT TYPE=RESET VALUE="CLEAR FORM">
 
</FORM>
 
</TD>
</TR></TABLE>
</BODY>
</HTML>
[+][-]07.05.2008 at 02:15PM PDT, ID: 21938403

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.05.2008 at 02:24PM PDT, ID: 21938425

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.05.2008 at 02:36PM PDT, ID: 21938456

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.05.2008 at 02:52PM PDT, ID: 21938497

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.09.2008 at 07:58AM PDT, ID: 21964347

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.09.2008 at 08:12AM PDT, ID: 21964538

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.13.2008 at 05:44AM PDT, ID: 21992323

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.13.2008 at 11:41AM PDT, ID: 21993649

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.13.2008 at 03:48PM PDT, ID: 21994601

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.14.2008 at 02:54AM PDT, ID: 21996763

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.14.2008 at 03:57AM PDT, ID: 21996973

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.17.2008 at 04:21AM PDT, ID: 22024167

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.23.2008 at 12:49AM PDT, ID: 22066862

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.23.2008 at 12:57AM PDT, ID: 22066894

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.23.2008 at 01:12AM PDT, ID: 22066960

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.23.2008 at 07:23AM PDT, ID: 22069578

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.23.2008 at 07:50AM PDT, ID: 22069910

View this solution now by starting your 14-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: JavaScript, Hypertext Markup Language (HTML), PHP Scripting Language
Tags: Javascript, PHP, HTML
Sign Up Now!
Solution Provided By: mms_master
Participating Experts: 1
Solution Grade: A
 
 
[+][-]07.23.2008 at 10:33AM PDT, ID: 22071726

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.23.2008 at 10:34AM PDT, ID: 22071738

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.24.2008 at 11:29AM PDT, ID: 22082081

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.24.2008 at 11:40AM PDT, ID: 22082181

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.24.2008 at 11:45AM PDT, ID: 22082234

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.24.2008 at 11:47AM PDT, ID: 22082245

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-43 / EE_QW_2_20070628