Solved

Math Javascript form

Posted on 2000-03-26
9
169 Views
Last Modified: 2008-02-26
I want to be able to enter an like the following:
             Amount       Cost       Total
Cost of      1    X  $27.00 =have total automaticly  place total here
Cost of      1    X  $27.00 =have total automaticly  place total here
Cost of      1    X  $27.00 =have total automaticly  place total here
Cost of      1    X  $27.00 =have total automaticly  place total here
Grand Total=have total automaticly  place total here
Also would like to be able to change the amount on screen of each
and have it total and grand total would also up date.
Thank you      
0
Comment
Question by:starview
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
9 Comments
 
LVL 1

Expert Comment

by:bculver98
ID: 2658295
Here you go: (Just copy and paste the code below)
Brian
----------------------------------

<HTML>
<TITLE></TITLE>
<BODY>
<SCRIPT language="javascript">
function updateall()
{
      amt = eval(amount1.value);
    cst = eval(cost1.value);
      ttl1 = amt*cst;
      
      amt = eval(amount2.value);
      cst = eval(cost2.value);
      ttl2 = amt*cst;

      amt = eval(amount3.value);
      cst = eval(cost3.value);
      ttl3 = amt*cst;

      amt = eval(amount4.value);
      cst = eval(cost4.value);
      ttl4 = amt*cst;
      
      total1.value = ttl1;
      total2.value = ttl2;
      total3.value = ttl3;
      total4.value = ttl4;

      grandtotal.value = eval(total1.value) + eval(total2.value) + eval(total3.value) + eval(total4.value);
      
      //grandtotal.value = ttl1 + ttl2 + ttl3 + ttl4;
}
</SCRIPT>
<CENTER>
<TABLE border="1">
<TR><TD>
<TABLE border="0">
<TR>
      <TD>&nbsp;&nbsp;&nbsp;</TD>
      <TD>&nbsp;</TD>
      <TD align=center>Amount</TD>
      <TD>&nbsp;&nbsp;&nbsp;</TD>
      <TD align=center>Cost</TD>
      <TD>&nbsp;&nbsp;&nbsp;</TD>
      <TD align=center>Total</TD>
</TR>
<TR>
      <TD align=center>Cost of</TD>
      <TD>&nbsp;</TD>
      <TD align=center><INPUT TYPE=Text name=amount1 value=1 size=3 onBlur="javascript:updateall();"></TD>
      <TD align=center>x</TD>
      <TD align=center><INPUT TYPE=Text name=cost1 value="27.00" size=6 onBlur="javascript:updateall();"></TD>
      <TD align=center>=&nbsp;$</TD>
      <TD align=center><INPUT TYPE=Text name=total1 size=7 onBlur="javascript:updateall();"></TD>
</TR>
<TR>
      <TD align=center>Cost of</TD>
      <TD>&nbsp;</TD>
      <TD align=center><INPUT TYPE=Text name=amount2 value=1 size=3 onBlur="javascript:updateall();"></TD>
      <TD align=center>x</TD>
      <TD align=center><INPUT TYPE=Text name=cost2 value="27.00" size=6 onBlur="javascript:updateall();"></TD>
      <TD align=center>=&nbsp;$</TD>
      <TD align=center><INPUT TYPE=Text name=total2 size=7 onBlur="javascript:updateall();"></TD>
</TR>
<TR>
      <TD align=center>Cost of</TD>
      <TD>&nbsp;</TD>
      <TD align=center><INPUT TYPE=Text name=amount3 value=1 size=3 onBlur="javascript:updateall();"></TD>
      <TD align=center>x</TD>
      <TD align=center><INPUT TYPE=Text name=cost3 value="27.00" size=6 onBlur="javascript:updateall();"></TD>
      <TD align=center>=&nbsp;$</TD>
      <TD align=center><INPUT TYPE=Text name=total3 size=7 onBlur="javascript:updateall();"></TD>
</TR>
<TR>
      <TD align=center>Cost of</TD>
      <TD>&nbsp;</TD>
      <TD align=center><INPUT TYPE=Text name=amount4 value=1 size=3 onBlur="javascript:updateall();"></TD>
      <TD align=center>x</TD>
      <TD align=center><INPUT TYPE=Text name=cost4 value="27.00" size=6 onBlur="javascript:updateall();"></TD>
      <TD align=center>=&nbsp;$</TD>
      <TD align=center><INPUT TYPE=Text name=total4 size=7 onBlur="javascript:updateall();"></TD>
</TR>
<TR>
      <TD colspan=5 align=right>Grand Total</TD><TD align=center>=&nbsp;$</TD>
      <TD><INPUT TYPE=Text name=grandtotal size=8 onBlur="javascript:updateall();"></TD>
</TR>
</TABLE>
</TD></TR>
</TABLE>
</CENTER>
</BODY>
<SCRIPT language="javascript">
  updateall();
</SCRIPT>
</HTML>
0
 

Author Comment

by:starview
ID: 2659224
I have tried to run this program put it only place
Cost of          X  $        =$     total
Cost of          X  $        =$     total
Cost of          X  $        =$     total
Cost of          X  $        =$     total

 I am not able to enter any amounts in the cost of area
or in the $ area
Other word it only display not a working model
Sorry
0
 
LVL 9

Expert Comment

by:TTom
ID: 2659444
starview:

Not sure what you may have done wrong, but I copied this code into a new document, and it worked perfectly.

You should probably try again.

Tom
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:bculver98
ID: 2659662
Are you using some other browser besides IE?  I tested the code carefully.  I'm sure it works, maybe your problem lies in a disabled option.  If your using IE, set the option to run Javascript.
0
 

Author Comment

by:starview
ID: 2662029
Hi
Is there a reason why this will not work with Netcape browser.
0
 
LVL 1

Expert Comment

by:bculver98
ID: 2662442
no, not really ... only if the browser doesn't support javascript
0
 
LVL 1

Expert Comment

by:bculver98
ID: 2662456
I was refering to a browser like Opera, Amaya or any other.

Here's a list of some of the one's out there: (this covers several platforms)

http://browserwatch.internet.com/browsers/browsers-big.html

This is for the list of Windows supported Browsers:

http://browserwatch.internet.com/browsers/browsers-win.html
0
 
LVL 1

Expert Comment

by:bculver98
ID: 2662465
I don't know else to say.  That code works as far as I know your problem lies else where.
0
 
LVL 1

Accepted Solution

by:
bculver98 earned 70 total points
ID: 2662676
Have you tried the code... in a new page.  I know the code works!!!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Use Mid in Html 6 23
Triple line in an alert message 4 24
arrays and radio buttons 10 40
How to get text of href without any ID using Javascript 9 26
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question