![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||||
| |||||
|
|
I have written a form which collects input for a fare calculation. The form collects the following: |
|
The following is the form and the Javascript, but I cannot get it to work. |
|
script type=text/javascript function calculate() { if (document.quote.Group.value = 1) then Var farepp = 80; else if (document.quote.Group.value = 2) then Var farepp = 70; else Var farepp = 60; |
|
var Adults = document.quote.Adults.value; var Chil412 = document.quote.Chil412.value; var ChilU4 = document.quote.ChilU4.value; var totalpass = Math.pow(Adults+Chil412+ChiU4); var totalfare = Math.pow((farepp*Adults)+(Chil412*farepp/2)); |
|
document.quote.totalpass.value=""; document.quote.totalfare.value=""; } /script |
#2
| |||
| |||
|
|
I have written a form which collects input for a fare calculation. The form collects the following: snip assignment The following is the form and the Javascript, but I cannot get it to work. That's not good enough... next time state clearly: 1. What results do you expect 2. What incorrect results you're getting I'll give you some hints below. script type=text/javascript function calculate() { if (document.quote.Group.value = 1) then Var farepp = 80; else if (document.quote.Group.value = 2) then Var farepp = 70; else Var farepp = 60; 1. JavaScript does not have a "then" keyword. 2. JavaScript, while loosely typed, are case-sensitive. 3. Scope rules: What scope do you want fareapp to be in? var Adults = document.quote.Adults.value; var Chil412 = document.quote.Chil412.value; var ChilU4 = document.quote.ChilU4.value; var totalpass = Math.pow(Adults+Chil412+ChiU4); var totalfare = Math.pow((farepp*Adults)+(Chil412*farepp/2)); There's a typo in one of the above lines... should be obvious when you see the error message. document.quote.totalpass.value=""; document.quote.totalfare.value=""; } /script You want to display the results, right? Then you shouldn't assign empty strings to the fields here. BTW the calculation is incorrect too... results in NaN. I'll leave that part for you to fix... it looks like a "squish-the-bugs" kind of assignment to me. KC |
#3
| |||
| |||
|
|
var totalfare = Math.pow((farepp*Adults)+(farepp*Chil412/2)); var totalpass = Math.pow(Adults+Chil412+ChilU4); function round(totalfare) {return Math.round(totalfare *100)/100;} |
|
Am I missing something obvious here? |
|
"KC Wong" <sterilize.the.spammers (AT) killkillkill (DOT) com> wrote in message news:bkrnp2$506v1$1 (AT) ID-200690 (DOT) news.uni-berlin.de... |
![]() |
| Thread Tools | |
| Display Modes | |
| |