javascript calculation total not working
-
Hi there, I really hope you can help I have worked on this all day today and last night. I can't get the Total box to calculate. I am trying to create an online invoice for my customer to print from my web page. I have scoured the internet looking for some help, but it doesn't help that I am clueless about javascript. This is what I have tried: In my table, all I want to happen is for the user to type in a price in the Amount boxes and then have a total at the bottom. Seems pretty basic, but I just don't understand why it won't work (not really sure of what I am doing) Can somebody please help me? The form itself can be found at www.ahtcsonline.com/invoice.html - the source is too much to copy so it may be easier to view the form and then view the source code underneath it. Thank you in advance, Evan <script type="text/javascript"> function totalamountdue(){ { var amount, amount2, amount3, amount4, amount5, amount6, amount7, amount8, amount9, amount10; Amount = document.Invamt.Amount.value; Amount2 = document.Invamt.Amount2.value; Amount3 = document.Invamt.Amount3.value; Amount4 = document.Invamt.Amount4.value; Amount5 = document.Invamt.Amount5.value; Amount6 = document.Invamt.Amount6.value; Amount7 = document.Invamt.Amount7.value; Amount8 = document.Invamt.Amount8.value; Amount9 = document.Invamt.Amount9.value; Amount10 = document.Invamt.Amount10.value; Total = document.Invamt.Total.value; document.Invamt.Total.value = (amount + amount2 + amount3 + amount4 + amount5 + amount6 + amount7 + amount8 + amount9 + amount10); } } </script>
-
Hi there, I really hope you can help I have worked on this all day today and last night. I can't get the Total box to calculate. I am trying to create an online invoice for my customer to print from my web page. I have scoured the internet looking for some help, but it doesn't help that I am clueless about javascript. This is what I have tried: In my table, all I want to happen is for the user to type in a price in the Amount boxes and then have a total at the bottom. Seems pretty basic, but I just don't understand why it won't work (not really sure of what I am doing) Can somebody please help me? The form itself can be found at www.ahtcsonline.com/invoice.html - the source is too much to copy so it may be easier to view the form and then view the source code underneath it. Thank you in advance, Evan <script type="text/javascript"> function totalamountdue(){ { var amount, amount2, amount3, amount4, amount5, amount6, amount7, amount8, amount9, amount10; Amount = document.Invamt.Amount.value; Amount2 = document.Invamt.Amount2.value; Amount3 = document.Invamt.Amount3.value; Amount4 = document.Invamt.Amount4.value; Amount5 = document.Invamt.Amount5.value; Amount6 = document.Invamt.Amount6.value; Amount7 = document.Invamt.Amount7.value; Amount8 = document.Invamt.Amount8.value; Amount9 = document.Invamt.Amount9.value; Amount10 = document.Invamt.Amount10.value; Total = document.Invamt.Total.value; document.Invamt.Total.value = (amount + amount2 + amount3 + amount4 + amount5 + amount6 + amount7 + amount8 + amount9 + amount10); } } </script>
Try this: function totalamountdue(){ var Amount = document.getElementById("Amount").value; var Amount2 = document.getElementById("Amount2").value; var Amount3 = document.getElementById("Amount3").value; var Amount4 = document.getElementById("Amount4").value; var Amount5 = document.getElementById("Amount5").value; var Amount6 = document.getElementById("Amount6").value; var Amount7 = document.getElementById("Amount7").value; var Amount8 = document.getElementById("Amount8").value; var Amount9 = document.getElementById("Amount9").value; var Amount10 = document.getElementById("Amount10").value; document.getElementById("Total").value = amount + amount2 + amount3 + amount4 + amount5 + amount6 + amount7 + amount8 + amount9 + amount10; } We really should add some error handling and/or only allow numbers in the text boxes.
-
Try this: function totalamountdue(){ var Amount = document.getElementById("Amount").value; var Amount2 = document.getElementById("Amount2").value; var Amount3 = document.getElementById("Amount3").value; var Amount4 = document.getElementById("Amount4").value; var Amount5 = document.getElementById("Amount5").value; var Amount6 = document.getElementById("Amount6").value; var Amount7 = document.getElementById("Amount7").value; var Amount8 = document.getElementById("Amount8").value; var Amount9 = document.getElementById("Amount9").value; var Amount10 = document.getElementById("Amount10").value; document.getElementById("Total").value = amount + amount2 + amount3 + amount4 + amount5 + amount6 + amount7 + amount8 + amount9 + amount10; } We really should add some error handling and/or only allow numbers in the text boxes.
Hi There Jason, I wished it worked, I was really hoping but nothing calculated when I hit the "calculate" button. I want you to also know that I have tried so many iterations before I asked for help. I am very tenacious and still looked on the net after my submission. Wish I knew what I was doing but I truly think that the subject is over my head. Although I did create my website from scratch back in August and I knew nothing of HTML...not that I know that much now ;) Thank you for trying, Evan
-
Hi there, I really hope you can help I have worked on this all day today and last night. I can't get the Total box to calculate. I am trying to create an online invoice for my customer to print from my web page. I have scoured the internet looking for some help, but it doesn't help that I am clueless about javascript. This is what I have tried: In my table, all I want to happen is for the user to type in a price in the Amount boxes and then have a total at the bottom. Seems pretty basic, but I just don't understand why it won't work (not really sure of what I am doing) Can somebody please help me? The form itself can be found at www.ahtcsonline.com/invoice.html - the source is too much to copy so it may be easier to view the form and then view the source code underneath it. Thank you in advance, Evan <script type="text/javascript"> function totalamountdue(){ { var amount, amount2, amount3, amount4, amount5, amount6, amount7, amount8, amount9, amount10; Amount = document.Invamt.Amount.value; Amount2 = document.Invamt.Amount2.value; Amount3 = document.Invamt.Amount3.value; Amount4 = document.Invamt.Amount4.value; Amount5 = document.Invamt.Amount5.value; Amount6 = document.Invamt.Amount6.value; Amount7 = document.Invamt.Amount7.value; Amount8 = document.Invamt.Amount8.value; Amount9 = document.Invamt.Amount9.value; Amount10 = document.Invamt.Amount10.value; Total = document.Invamt.Total.value; document.Invamt.Total.value = (amount + amount2 + amount3 + amount4 + amount5 + amount6 + amount7 + amount8 + amount9 + amount10); } } </script>
function totalamountdue() {
var inputs = document.getElementsByTagName("INPUT");
var runningTotal = 0;
for (i = 0; i < inputs.length; i++) {
if (inputs[i].id == "total") {
inputs[i].value = runningTotal / 100;
var a = inputs[i].value.split(".");
if (!a[1]) {inputs[i].value += ".00"}
else if (a[1].indexOf("0") != 0 && a[1] < 10) { inputs[i].value += "0" }
}
if (inputs[i].id.indexOf("Amount") == 0) {
if (/^[1-9][0-9]{0,2}(,[0-9]{3})*(\.[0-9]{2})?$/.test(inputs[i].value)) {
runningTotal += +inputs[i].value * 100;
} else {
if (inputs[i].value == "THIS IS A BAD VALUE") { inputs[i].value = ""; }
if (inputs[i].value) { inputs[i].value = "THIS IS A BAD VALUE"; }
}
}} } <>
-- Modified Friday, February 26, 2010 1:35 AM
-
function totalamountdue() {
var inputs = document.getElementsByTagName("INPUT");
var runningTotal = 0;
for (i = 0; i < inputs.length; i++) {
if (inputs[i].id == "total") {
inputs[i].value = runningTotal / 100;
var a = inputs[i].value.split(".");
if (!a[1]) {inputs[i].value += ".00"}
else if (a[1].indexOf("0") != 0 && a[1] < 10) { inputs[i].value += "0" }
}
if (inputs[i].id.indexOf("Amount") == 0) {
if (/^[1-9][0-9]{0,2}(,[0-9]{3})*(\.[0-9]{2})?$/.test(inputs[i].value)) {
runningTotal += +inputs[i].value * 100;
} else {
if (inputs[i].value == "THIS IS A BAD VALUE") { inputs[i].value = ""; }
if (inputs[i].value) { inputs[i].value = "THIS IS A BAD VALUE"; }
}
}} } <>
-- Modified Friday, February 26, 2010 1:35 AM
Dave, I could hug you...or just give you five! Thank you and the previous person, Jason for all of your efforts. I hate to ask for help, but there was no way I was going to get this one. Sometimes I come up with these ambitious ideas but with no way to implement them. Thank you very much, Evan Einhorn
-
Dave, I could hug you...or just give you five! Thank you and the previous person, Jason for all of your efforts. I hate to ask for help, but there was no way I was going to get this one. Sometimes I come up with these ambitious ideas but with no way to implement them. Thank you very much, Evan Einhorn
stay tenacious
-
function totalamountdue() {
var inputs = document.getElementsByTagName("INPUT");
var runningTotal = 0;
for (i = 0; i < inputs.length; i++) {
if (inputs[i].id == "total") {
inputs[i].value = runningTotal / 100;
var a = inputs[i].value.split(".");
if (!a[1]) {inputs[i].value += ".00"}
else if (a[1].indexOf("0") != 0 && a[1] < 10) { inputs[i].value += "0" }
}
if (inputs[i].id.indexOf("Amount") == 0) {
if (/^[1-9][0-9]{0,2}(,[0-9]{3})*(\.[0-9]{2})?$/.test(inputs[i].value)) {
runningTotal += +inputs[i].value * 100;
} else {
if (inputs[i].value == "THIS IS A BAD VALUE") { inputs[i].value = ""; }
if (inputs[i].value) { inputs[i].value = "THIS IS A BAD VALUE"; }
}
}} } <>
-- Modified Friday, February 26, 2010 1:35 AM
function totalamountdue() { var inputs = document.getElementsByTagName("INPUT"); var runningTotal = 0; for (i = 0; i < inputs.length; i++) { if (inputs[i].id == "total") { inputs[i].value = runningTotal / 100; var a = inputs[i].value.split("."); if (!a[1]) {inputs[i].value += ".00"} else if (a[1].indexOf("0") != 0 && a[1] < 10) { inputs[i].value += "0" } } if (inputs[i].id.indexOf("Amount") == 0) { if (/^[1-9][0-9]{0,2}(,[0-9]{3})*(\.[0-9]{2})?$/.test(inputs[i].value)) { runningTotal += +inputs[i].value * 100; } else { if (inputs[i].value == "THIS IS A BAD VALUE") { inputs[i].value = ""; } if (inputs[i].value) { inputs[i].value = "THIS IS A BAD VALUE"; } } } } }
-
Hi there, I really hope you can help I have worked on this all day today and last night. I can't get the Total box to calculate. I am trying to create an online invoice for my customer to print from my web page. I have scoured the internet looking for some help, but it doesn't help that I am clueless about javascript. This is what I have tried: In my table, all I want to happen is for the user to type in a price in the Amount boxes and then have a total at the bottom. Seems pretty basic, but I just don't understand why it won't work (not really sure of what I am doing) Can somebody please help me? The form itself can be found at www.ahtcsonline.com/invoice.html - the source is too much to copy so it may be easier to view the form and then view the source code underneath it. Thank you in advance, Evan <script type="text/javascript"> function totalamountdue(){ { var amount, amount2, amount3, amount4, amount5, amount6, amount7, amount8, amount9, amount10; Amount = document.Invamt.Amount.value; Amount2 = document.Invamt.Amount2.value; Amount3 = document.Invamt.Amount3.value; Amount4 = document.Invamt.Amount4.value; Amount5 = document.Invamt.Amount5.value; Amount6 = document.Invamt.Amount6.value; Amount7 = document.Invamt.Amount7.value; Amount8 = document.Invamt.Amount8.value; Amount9 = document.Invamt.Amount9.value; Amount10 = document.Invamt.Amount10.value; Total = document.Invamt.Total.value; document.Invamt.Total.value = (amount + amount2 + amount3 + amount4 + amount5 + amount6 + amount7 + amount8 + amount9 + amount10); } } </script>
I know you have already been given a solution to this, but I just thought I give you an important tip. This didn't work because you are declaring and adding variables with a lowercase 'a' in amount, but assigning the values to an uppercase Amount. This makes them different variables. Amount != amount. JavaScript is case sensitive.
Words fade as the meanings change, but somehow, it don't bother me.
-
I know you have already been given a solution to this, but I just thought I give you an important tip. This didn't work because you are declaring and adding variables with a lowercase 'a' in amount, but assigning the values to an uppercase Amount. This makes them different variables. Amount != amount. JavaScript is case sensitive.
Words fade as the meanings change, but somehow, it don't bother me.
Hi Boro_Bob, I really appreciate the information. Last August I lost my job and then decided that I would do my own thing. I knew I needed a website so I started working on it. I knew absolutely nothing about HTML. Little by little I have learned along the way and I borrowed lots of code I found on the net but only employed it if I could get it to work. Instructions varied so if it worked great if not I moved on. Javascript...not a clue. But again I scoured the internet to make my column add up and tried many different iterations. I should have known what you said to be true about the code being case sensitive...as it is true for HTML. During the course of building my website I had decided to capitalize the first letter of the file names when I was done editing so I could keep track of what was done. Lesson learned, never capitalize the "I" in index.html or it will give you a 404 Error code and the Home page won't work.LOL. My web page has been about scope creep, every time I get something to work I then think of something to make it better. For instance, the columns adding up now works great...my next idea was to have drop downs with the 3 or so varying amounts I charge for my online classes. You know I had to try it but since I don't know squat about JS I gave up my idea. Again I want to say "thank you" for explaining that JS was case sensitive. I tried like hell to figure it out on my own and that never dawned on me. Evan Einhorn www.AHTCSonline.com
-
Hi Boro_Bob, I really appreciate the information. Last August I lost my job and then decided that I would do my own thing. I knew I needed a website so I started working on it. I knew absolutely nothing about HTML. Little by little I have learned along the way and I borrowed lots of code I found on the net but only employed it if I could get it to work. Instructions varied so if it worked great if not I moved on. Javascript...not a clue. But again I scoured the internet to make my column add up and tried many different iterations. I should have known what you said to be true about the code being case sensitive...as it is true for HTML. During the course of building my website I had decided to capitalize the first letter of the file names when I was done editing so I could keep track of what was done. Lesson learned, never capitalize the "I" in index.html or it will give you a 404 Error code and the Home page won't work.LOL. My web page has been about scope creep, every time I get something to work I then think of something to make it better. For instance, the columns adding up now works great...my next idea was to have drop downs with the 3 or so varying amounts I charge for my online classes. You know I had to try it but since I don't know squat about JS I gave up my idea. Again I want to say "thank you" for explaining that JS was case sensitive. I tried like hell to figure it out on my own and that never dawned on me. Evan Einhorn www.AHTCSonline.com