[Javascript] form query

Peter Brunone peter at brunone.com
Wed Oct 1 01:07:21 CDT 2003


Hi Frank,

    I've corrected some of your syntax errors and one or two coding
problems (if I sound a bit pedantic, don't take it personally):

1)  You are trying to define an array with brackets when you must use
parentheses, just like defining any other object with parameters.  When
you refer to individual, array elements, *then* you use brackets.

2)  Make sure you increment your counter variable (in this case, i) or
your loop will go on forever!

3)  Generally, you should include a semicolon at the end of each line;
it's the Javascript standard and some browsers will break if you don't
do it (exceptions are where you define a conditional statement, like
if/while/for); I've put semicolons everywhere they should be in your
script so you can see where to put them and where not to put them.

    Things I haven't corrected are the fact that you are passing the
form to the calc() function, but then never using it.  I don't know what
"num" is supposed to be, but you need to refer to the form and find out
which field contains which value, and then match it to the correct price
(you may be trying to do this with the qty() array, but it's hard to
tell at this stage.

    Since it's quite possible that you just haven't gotten to some of
these yet, feel free to ignore my rantings and go on, but do pay
attention to items 1-3 above.  Let us know if you need any more help...

Cheers,

Peter
-----Original Message-----
From: javascript-bounces at LaTech.edu
[mailto:javascript-bounces at LaTech.edu] On Behalf Of Frank Davie


Dear Javascript List,
I am teaching myself javascripting and have decided to tackle this form
menu, I have to display the totals, days,and email confirm.
The only thing is I cannot get the script far enough to calculate the
total, I get an error message saying product.length is null or not an
object.
Could you possibly give me a solution to calculate and display the
subtotal and total so I can move on to the days and email calcs.

thanks

p.s 

I have enclosed the form 




function calc(f){  
 var qty = new Array();
 var subtotal;
 
 var total = 0;
 var i = 0;
 var num= 1;

 while ( num !=0 && i < product.length) {
  qty[i] = num;
               subtotal = subtotal + qty[i] * prices[i]
  
 
 
                                               }

                        }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20031001/f0e50b06/attachment.html>


More information about the Javascript mailing list