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
Solved

Addition with Java script

Posted on 2001-06-13
5
226 Views
Last Modified: 2010-03-31
I have a simple form that calculates and adds items into a "Total" field.

How do I add a fixed amount for delivery?

Here is the code for the last of twenty items and the code for the Total.

<TD align=right width="25%"><FONT face=Arial
  size=3>Professional</FONT></TD>
<TD align=right width="30%"><B><FONT face=Arial
  size=3>$435.00</FONT></B></TD>
<TD width=50><INPUT
  onchange=this.form.total.value=checkChoice(this); size=3 value=0
  name=KP price="435.00" priorval="0"> </TD></TR>
    <TR>

    <TR>
<TD width="85%" colspan="4"><B><FONT face=Arial
  size=3>Total:
  <INPUT readOnly size=12
  name=total></FONT></B>

Many thanks,

robinski
0
Comment
Question by:robinski
  • 3
  • 2
5 Comments
 
LVL 5

Expert Comment

by:djbusychild
ID: 6188725
this is a javaSCRIPT question...
there must be code that updates the total value you have to modify that code so that you add the fixed delivery fee to it.. I can't figure it out from just this snippet
0
 

Author Comment

by:robinski
ID: 6189343
OOOOPS

My apology this must be the missing piece:

   <!-- Begin
   function checkChoice(whichbox) {
   with (whichbox.form) {
   if (isNaN(whichbox.value)) {
   whichbox.value = whichbox.priorval;
   whichbox.focus();
   }
   whichbox.value = Math.abs(whichbox.value);
   var dec = whichbox.value.indexOf('.', 1)
   if (dec > 0) {
   alert('No decimal places allowed for \"' +whichbox.name +'\" !');
   whichbox.value = whichbox.priorval;
   whichbox.focus();
   }
   hiddentotal.value = eval(hiddentotal.value) - eval(whichbox.price * whichbox.priorval);
   whichbox.priorval = whichbox.value;
   hiddentotal.value = eval(hiddentotal.value) + eval(whichbox.price * whichbox.value);
   return(formatCurrency(hiddentotal.value));
     }
   }
   function formatCurrency(num) {
   num = num.toString().replace(/\$|\,/g,'');
   if(isNaN(num)) num = "0";
   cents = Math.floor((num * 100 + 0.5) % 100);
   num = Math.floor((num * 100 + 0.5) / 100).toString();
   if(cents < 10) cents = "0" + cents;
   for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
   num = num.substring(0,num.length - (4 * i + 3))+','+num.substring(num.length-(4 * i + 3));
   return ("$" + num + "." + cents);
   }
   function InitForm() {
   document.myform.total.value = '$0';
   document.myform.hiddentotal.value = 0;
   for (xx = 0; xx < document.myform.elements.length; xx++) {
   if (document.myform.elements[xx].type == 'text') {
   document.myform.elements[xx].value = 0;
     }
   }
  }

   //  End -->
0
 
LVL 5

Accepted Solution

by:
djbusychild earned 100 total points
ID: 6189677
hiddentotal.value = eval(hiddentotal.value) + eval(whichbox.price * whichbox.value);
  return(formatCurrency(hiddentotal.value));

the above line should be changed to

hiddentotal.value = eval(hiddentotal.value) + eval(whichbox.price * whichbox.value) + 50;
  return(formatCurrency(hiddentotal.value));

where 50 is your shipping.. change it to whatever your shipping cost is
0
 

Author Comment

by:robinski
ID: 6193111
Very many thanks. You help is appreciated
0
 

Author Comment

by:robinski
ID: 6193192
Very many thanks. You help is appreciated
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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
Arrays.asList  VS  ArrayList 4 71
nextBoolean(double p) for Random class 3 41
egit plugin on eclipse 8 82
java mysql insert application 14 28
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

860 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