I have an order form at
http://www.develop.check.com.au/hara/products_prices2.php where
subtotals are calculated by JS as soon as somebody enters a quantity.
I would like also to display a running grand total at the top next to
the Submit button but I can't get that bit to work.
The JS file is at
http://www.develop.check.com.au/hara/js/products_prices.js
The site is under development so:
User name: java
Password: script
Many thanks in advance
|
|
0
|
|
|
|
Reply
|
Howard
|
11/23/2008 4:44:12 AM |
|
"Howard Martin" <css@koalanet.com.au> wrote in message
news:kfnhi4t33isemri38k46if4ube3c8jlvkd@4ax.com...
>I have an order form at
> http://www.develop.check.com.au/hara/products_prices2.php where
> subtotals are calculated by JS as soon as somebody enters a quantity.
>
> I would like also to display a running grand total at the top next to
> the Submit button but I can't get that bit to work.
>
> The JS file is at
> http://www.develop.check.com.au/hara/js/products_prices.js
>
> The site is under development so:
> User name: java
> Password: script
>
> Many thanks in advance
I hesitate to reply because one has to abide by so much protocol or get shot
down in flames. But, it should not be a problem.
Would you mind also posting the HTML, or at least the form to save me from
having to construct a new one?
--
Trevor Lawrence
Canberra
Web Site http://trevorl.mvps.org
|
|
0
|
|
|
|
Reply
|
Trevor
|
11/23/2008 5:09:30 AM
|
|
On Nov 22, 11:44=A0pm, Howard Martin <c...@koalanet.com.au> wrote:
> I have an order form athttp://www.develop.check.com.au/hara/products_pric=
es2.phpwhere
> subtotals are calculated by JS as soon as somebody enters a quantity.
>
> I would like also to display a running grand total at the top next to
> the Submit button but I can't get that bit to work.
>
> The JS file is athttp://www.develop.check.com.au/hara/js/products_prices.=
js
Looks like a syntax error to me.
>
> The site is under development so:
> User name: java
> Password: script
That was really lame of you.
[snip]
|
|
0
|
|
|
|
Reply
|
David
|
11/23/2008 5:16:54 AM
|
|
"Trevor Lawrence" <Trevor L.@Canberra> wrote in message
news:newscache$tzsrak$7bf$1@news.grapevine.com.au...
> "Howard Martin" <css@koalanet.com.au> wrote in message
> news:kfnhi4t33isemri38k46if4ube3c8jlvkd@4ax.com...
>>I have an order form at
>> http://www.develop.check.com.au/hara/products_prices2.php where
>> subtotals are calculated by JS as soon as somebody enters a quantity.
>>
>> I would like also to display a running grand total at the top next to
>> the Submit button but I can't get that bit to work.
>>
>> The JS file is at
>> http://www.develop.check.com.au/hara/js/products_prices.js
>>
>> The site is under development so:
>> User name: java
>> Password: script
>>
>> Many thanks in advance
>
> I hesitate to reply because one has to abide by so much protocol or get
> shot down in flames. But, it should not be a problem.
>
> Would you mind also posting the HTML, or at least the form to save me from
> having to construct a new one?
>
Soory, I missed the URL at the top
What is wrong (so I think) is that quantTotal is not used
Try this
function total( what, number ) {
// var quantTotal = 0;
var grandTotal = 0;
var subtotal = 0; // Declare subtotal here
var el = what.elements; // New variable for shorter code
for ( var i=0; i<number; i++ ) {
if (el['quantity'+i].value == parseInt(el['quantity'+i].value)) {
if ( el['price' + i].value == '') {
el['price' + i].value = ''; // fix for Opera.
}
// quantTotal += el['quantity'+i].value * 1;
subtotal = el['quantity'+i].value * el['price'+i].value;
el['subtotal'+i].value = roundoff( subtotal );
grandTotal += +subtotal;
}
else {
el['subtotal'+i].value = "";
}
}
// what.quantTotal.value = quantTotal;
what.grandTotal.value = roundoff( grandTotal );
}
--
Trevor Lawrence
Canberra
Web Site http://trevorl.mvps.org
|
|
0
|
|
|
|
Reply
|
Trevor
|
11/23/2008 6:06:47 AM
|
|
On Nov 23, 1:06=A0am, "Trevor Lawrence" <Trevor L.@Canberra> wrote:
> "Trevor Lawrence" <Trevor L.@Canberra> wrote in messagenews:newscache$tzs=
rak$7bf$1@news.grapevine.com.au...
>
>
>
> > "Howard Martin" <c...@koalanet.com.au> wrote in message
> >news:kfnhi4t33isemri38k46if4ube3c8jlvkd@4ax.com...
> >>I have an order form at
> >>http://www.develop.check.com.au/hara/products_prices2.phpwhere
> >> subtotals are calculated by JS as soon as somebody enters a quantity.
>
> >> I would like also to display a running grand total at the top next to
> >> the Submit button but I can't get that bit to work.
>
> >> The JS file is at
> >>http://www.develop.check.com.au/hara/js/products_prices.js
>
> >> The site is under development so:
> >> User name: java
> >> Password: script
>
> >> Many thanks in advance
>
> > I hesitate to reply because one has to abide by so much protocol or get
> > shot down in flames. But, it should not be a problem.
>
> > Would you mind also posting the HTML, or at least the form to save me f=
rom
> > having to construct =A0a new one?
>
> Soory, I missed the URL at the top
>
> What is wrong (so I think) is that quantTotal is not used
> Try this
>
> function total( what, number ) {
> =A0 // var quantTotal =3D 0;
> =A0 var grandTotal =3D 0;
> =A0 var subtotal =A0 =3D 0; =A0 =A0 =A0// Declare subtotal here
> =A0 var el =3D what.elements; =A0// New variable for shorter code
>
> =A0 for ( var i=3D0; i<number; i++ ) {
> =A0 =A0 if (el['quantity'+i].value =3D=3D parseInt(el['quantity'+i].value=
)) {
Always specify a radix with parseInt. And what sort of screwy
concoction is this comparison?
> =A0 =A0 =A0 if ( el['price' + i].value =3D=3D '') {
> =A0 =A0 =A0 =A0 el['price' + i].value =3D ''; // fix for Opera.
What?!
> =A0 =A0 =A0 }
> =A0 =A0 =A0 // quantTotal +=3D el['quantity'+i].value * 1;
> =A0 =A0 =A0 subtotal =3D el['quantity'+i].value * el['price'+i].value;
Now that is really unfortunate.
> =A0 =A0 =A0 el['subtotal'+i].value =3D roundoff( subtotal );
>
> =A0 =A0 =A0 grandTotal +=3D +subtotal;
I don't think I've seen such confused rubbish in my life.
[snip]
Don't try *this* at home.
|
|
0
|
|
|
|
Reply
|
David
|
11/23/2008 6:19:24 AM
|
|
"Howard Martin" <css@koalanet.com.au> wrote in message
news:kfnhi4t33isemri38k46if4ube3c8jlvkd@4ax.com...
>I have an order form at
> http://www.develop.check.com.au/hara/products_prices2.php where
> subtotals are calculated by JS as soon as somebody enters a quantity.
Download and install firebug and from now on use FF for initial development.
Firebug will immediately tell you that in line 73 of prices.js
what.quantTotal is undefined.
By the way you have not specified a background colour for that page. My puce
background shows through. And I simply can not read text at 11 pixels high.
|
|
0
|
|
|
|
Reply
|
rf
|
11/23/2008 8:14:02 AM
|
|
Howard Martin wrote:
> I have an order form at
> http://www.develop.check.com.au/hara/products_prices2.php where
> subtotals are calculated by JS as soon as somebody enters a quantity.
>
> I would like also to display a running grand total at the top next to
> the Submit button but I can't get that bit to work.
>
> The JS file is at
> http://www.develop.check.com.au/hara/js/products_prices.js
>
> The site is under development so:
> User name: java
> Password: script
>
> Many thanks in advance
I couldn't see where you were calling ANYTHING to be put into the field
next to the submit named grandTotal. Why not simply add id="grandTotal"
in your definition of that tag and have
document.getElementById('grandTotal').value = grandTotal
at the very end of your total function?
|
|
0
|
|
|
|
Reply
|
sheldonlg
|
11/23/2008 12:08:32 PM
|
|
In comp.lang.javascript message <newscache$anvrak$stn$1@news.grapevine.c
om.au>, Sun, 23 Nov 2008 06:06:47, Trevor Lawrence <Trevor@L.?.invalid>
posted:
> if (el['quantity'+i].value == parseInt(el['quantity'+i].value)) {
That is inefficient because it looks up el['quantity'+i].value twice.
It rejects 09, a potentially acceptable quantity.
It accepts -9; be aware that negative quantities are not commonly
supplied in commerce.
It accepts 3e0, which is IMHO more likely to be a typo than intended.
It accepts 0x0, ditto.
Before answering JavaScript questions, it's rather a good idea to learn
JavaScript.
Before dealing with validation, it is wise to learn how to use simple
RegExps.
Web Site http://trevorl.mvps.org gives two runtime errors on loading
(IE7. debugging on). Firefox says
Error: missing ; before statement
Source File: http://trevorl.mvps.org/scripts/external.js
Line: 12, Column: 29
Source Code:
var hometitle = 'Trevor L.'s Site'
Error: sendEMail is not defined
Source File: http://trevorl.mvps.org/
Line: 52
W3's TIDY (19 April 2007) gives 9 warnings.
--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)
|
|
0
|
|
|
|
Reply
|
Dr
|
11/23/2008 9:20:05 PM
|
|
Reply at bottom
"David Mark" <dmark.cinsoft@gmail.com> wrote in message
news:c50f08df-2473-44e0-83b0-1555ea67e5b5@a12g2000yqm.googlegroups.com...
On Nov 23, 1:06 am, "Trevor Lawrence" <Trevor L.@Canberra> wrote:
> "Trevor Lawrence" <Trevor L.@Canberra> wrote in
> messagenews:newscache$tzsrak$7bf$1@news.grapevine.com.au...
>
>
>
> > "Howard Martin" <c...@koalanet.com.au> wrote in message
> >news:kfnhi4t33isemri38k46if4ube3c8jlvkd@4ax.com...
> >>I have an order form at
> >>http://www.develop.check.com.au/hara/products_prices2.phpwhere
> >> subtotals are calculated by JS as soon as somebody enters a quantity.
>
> >> I would like also to display a running grand total at the top next to
> >> the Submit button but I can't get that bit to work.
>
> >> The JS file is at
> >>http://www.develop.check.com.au/hara/js/products_prices.js
>
> >> The site is under development so:
> >> User name: java
> >> Password: script
>
> >> Many thanks in advance
>
> > I hesitate to reply because one has to abide by so much protocol or get
> > shot down in flames. But, it should not be a problem.
>
> > Would you mind also posting the HTML, or at least the form to save me
> > from
> > having to construct a new one?
>
> Soory, I missed the URL at the top
>
> What is wrong (so I think) is that quantTotal is not used
> Try this
>
> function total( what, number ) {
> // var quantTotal = 0;
> var grandTotal = 0;
> var subtotal = 0; // Declare subtotal here
> var el = what.elements; // New variable for shorter code
>
> for ( var i=0; i<number; i++ ) {
> if (el['quantity'+i].value == parseInt(el['quantity'+i].value)) {
Always specify a radix with parseInt. And what sort of screwy
concoction is this comparison?
> if ( el['price' + i].value == '') {
> el['price' + i].value = ''; // fix for Opera.
What?!
> }
> // quantTotal += el['quantity'+i].value * 1;
> subtotal = el['quantity'+i].value * el['price'+i].value;
Now that is really unfortunate.
> el['subtotal'+i].value = roundoff( subtotal );
>
> grandTotal += +subtotal;
I don't think I've seen such confused rubbish in my life.
[snip]
Don't try *this* at home.
Reply
====
David,
I didn't want to alter the OP's code too much, ,just get it working.
Howard,
Would you like me to have a go at tidying up the code, or do David's
comments give you enough info. ?
(I don't have any idea as to what the fix for Opera is about, so I would
probably just delete it.)
--
Trevor Lawrence
Canberra
Web Site http://trevorl.mvps.org
|
|
0
|
|
|
|
Reply
|
Trevor
|
11/23/2008 10:55:35 PM
|
|
On Nov 23, 5:55=A0pm, "Trevor Lawrence" <Trevor L.@Canberra> wrote:
[snip]
>
> I didn't want to alter the OP's code too much, ,just get it working.
It wasn't clear whose code it was. When posting obviously bad code
(for whatever reason), it is best to include a disclaimer (e.g. I
didn't write or test this.)
[snip]
|
|
0
|
|
|
|
Reply
|
David
|
11/23/2008 11:03:24 PM
|
|
On Sun, 23 Nov 2008 06:06:47 GMT, "Trevor Lawrence" <Trevor
L.@Canberra> wrote:
>
>Soory, I missed the URL at the top
>
>What is wrong (so I think) is that quantTotal is not used
>Try this
That fixed it. Many thanks, Trevor,
Many thanks also to the others who replied - except the unhelpful, bad
tempered one. The lame, easy-to remember, easy-to type user name and
password have now been removed.
Howard
|
|
0
|
|
|
|
Reply
|
Howard
|
11/23/2008 11:03:57 PM
|
|
|
10 Replies
351 Views
(page loaded in 0.122 seconds)
|