Tlak

07-04-2003, 06:24 PM

I'm completely and totally new to Javascript, though I know BASIC (TI-82 flavor :p ) and did a few small programs in REALbasic.

I'm trying to create a calculator for a website that will take values inserted into form boxes, perform a mathematical operation, then return that variable to a different box.

The script is to calculate an estimated cost of putting in a patio--there are boxes for length, width, shape, and paver type. The "Shape" box has options for "round", "rectangle", or other. If it's "other", the total cost should be increased by 15%. Paver type is either "basic", "mid-range", or "high end", where the area is multiplied by a different number for each one.

I know nothing of JavaScript, but if it were in BASIC (combining TI-82 with REALbasic, as TI-82 doesn't have forms.. ), it'd look something like this: (Maybe it will help someone understand what I'm trying to do)

length.text*width.text=a

a*x(cost of base)=b

If paver.text="basic"

then

(a*1)+b=c

end

If paver.text="mid-range"

then

(a*2)+b=c

end

If paver.text="high end"

then

(a*3)+b=c

If shape.text /= (unequal to) "rectangle"

then

c*1.15=c

total.text=c

That's the sorta-kinda way I would do it, combining two variants of BASIC. Can someone help me figure out how to do this in Javascript? I'm reading tutorials, but still haven't found what I need.

I'm trying to create a calculator for a website that will take values inserted into form boxes, perform a mathematical operation, then return that variable to a different box.

The script is to calculate an estimated cost of putting in a patio--there are boxes for length, width, shape, and paver type. The "Shape" box has options for "round", "rectangle", or other. If it's "other", the total cost should be increased by 15%. Paver type is either "basic", "mid-range", or "high end", where the area is multiplied by a different number for each one.

I know nothing of JavaScript, but if it were in BASIC (combining TI-82 with REALbasic, as TI-82 doesn't have forms.. ), it'd look something like this: (Maybe it will help someone understand what I'm trying to do)

length.text*width.text=a

a*x(cost of base)=b

If paver.text="basic"

then

(a*1)+b=c

end

If paver.text="mid-range"

then

(a*2)+b=c

end

If paver.text="high end"

then

(a*3)+b=c

If shape.text /= (unequal to) "rectangle"

then

c*1.15=c

total.text=c

That's the sorta-kinda way I would do it, combining two variants of BASIC. Can someone help me figure out how to do this in Javascript? I'm reading tutorials, but still haven't found what I need.