Javascript Autocalculate Field not working in form

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
ojoc88
Forum Newbie
Posts: 12
Joined: Tue Oct 22, 2013 6:50 pm

Javascript Autocalculate Field not working in form

Post by ojoc88 »

Hi All,

My Javascript autocalculate field (scroll to bottom) not working in my form ( look at here >www[dot]ptsp[dot]my/form/demo-order.html )

But it will work in standalone html file ( look at here > www[dot]ptsp[dot]my/form/testautocalculate.html )

Anybody know how to fix this?

Thanks

Regards,
ojoc88
Last edited by ojoc88 on Tue Oct 22, 2013 9:34 pm, edited 2 times in total.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Javascript Autocalculate Field not working in form

Post by requinix »

Uncaught ReferenceError: test is not defined
demo-order.html:178

Code: Select all

function calculate() {
var p1, p2, p3;
p1 = test.price1.value * 1; // 178
p2 = test.price2.value * 1;
p3 = test.price3.value * 1;
p4 = test.price4.value * 1;
p5 = test.price5.value * 1;
p6 = test.price6.value * 1;
p7 = test.price7.value * 1;
total_price = p1 + p2 + p3 + p4 + p5 + p6 + p7;
test.total_price.value = cent(Math.round(total_price*Math.pow(10,2))/Math.pow(10,2));
}
ojoc88
Forum Newbie
Posts: 12
Joined: Tue Oct 22, 2013 6:50 pm

Re: Javascript Autocalculate Field not working in form

Post by ojoc88 »

requinix wrote:
Uncaught ReferenceError: test is not defined
demo-order.html:178

Code: Select all

function calculate() {
var p1, p2, p3;
p1 = test.price1.value * 1; // 178
p2 = test.price2.value * 1;
p3 = test.price3.value * 1;
p4 = test.price4.value * 1;
p5 = test.price5.value * 1;
p6 = test.price6.value * 1;
p7 = test.price7.value * 1;
total_price = p1 + p2 + p3 + p4 + p5 + p6 + p7;
test.total_price.value = cent(Math.round(total_price*Math.pow(10,2))/Math.pow(10,2));
}
Sir , please advice me. i'm not good in java
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Javascript Autocalculate Field not working in form

Post by requinix »

That's okay because Javascript isn't Java.

You tried to use the variable "test" but you didn't define it anywhere first. It was defined in the other page because it actually referred to the form (which was named "test") but you didn't do it that way in this page.
ojoc88
Forum Newbie
Posts: 12
Joined: Tue Oct 22, 2013 6:50 pm

Re: Javascript Autocalculate Field not working in form

Post by ojoc88 »

requinix wrote:That's okay because Javascript isn't Java.

You tried to use the variable "test" but you didn't define it anywhere first. It was defined in the other page because it actually referred to the form (which was named "test") but you didn't do it that way in this page.

But sir , why this page working fine > www[dot]ptsp[dot]my/form/testautocalculate.html

i copy paste the same coding.

thanks
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Javascript Autocalculate Field not working in form

Post by requinix »

Woah, that sounds like something really important I should have addressed in my reply.

Oh wait.
requinix wrote:It was defined in the other page because it actually referred to the form (which was named "test") but you didn't do it that way in this page.
ojoc88
Forum Newbie
Posts: 12
Joined: Tue Oct 22, 2013 6:50 pm

Re: Javascript Autocalculate Field not working in form

Post by ojoc88 »

requinix wrote:Woah, that sounds like something really important I should have addressed in my reply.

Oh wait.
requinix wrote:It was defined in the other page because it actually referred to the form (which was named "test") but you didn't do it that way in this page.
LOL .. sorry , my mistake . I should add " name="TEST" " in the " <form " code

thanks sir! :D
Post Reply