It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Please help with calculation

Please help with calculation

Postby edp1959 on Sun Feb 25, 2007 12:34 pm

I'm very new with javascript so I need help with what I think should be a very simple calculation. Here's what I'm trying to do:

Webpage contents:
drop down menu (S2) with set values for each item
drop down menu (S3) with set values for each item
form field (T1) for user input of number
push button (B3) to perform calculation
form field (T5) for calculation result

When the user selects items from S2 and S3 and puts a number in T1 then clicks B3 the result should show in T5.

This does not work correctly, the problem seems to be when I try to add 6 to y, because it gives me the correct answer with just y.

function ratings()
{
var t=document.cMount.S2.value;
var y=document.cMount.T1.value;
if (document.cMount.S3.value==12){
var Lmax=((2*t)*(146700/3))/y;}

if (document.cMount.S3.value==25){
var Lmax=((2*t)*(146700/3))/(y+6);}

if (document.cMount.S3.value==64){
var Lmax=((2*t)*(146700/3))/(y+6);}

document.cMount.T5.value=Lmax.toFixed(0);
edp1959
 
Posts: 4
Joined: Sun Feb 25, 2007 12:30 pm

Postby jntcomputers on Sun Feb 25, 2007 1:59 pm

So, what you're saying is you get the same answer as the first if statement where s3 == 12? Could be a problem with the form and not the calculations?
jntcomputers
 
Posts: 5
Joined: Sun Feb 25, 2007 5:42 am

Please help with calculation

Postby edp1959 on Sun Feb 25, 2007 2:07 pm

This gives me a correct value in T5, i.e. 2156
if (document.cMount.S3.value==12){
var Lmax=((2*t)*(146700/3))/y;}


The value these two give in T5 is NaN
if (document.cMount.S3.value==25){
var Lmax=((2*t)*(146700/3))/(y+6);}

if (document.cMount.S3.value==64){
var Lmax=((2*t)*(146700/3))/(y+6);}
edp1959
 
Posts: 4
Joined: Sun Feb 25, 2007 12:30 pm

Please help with calculation

Postby edp1959 on Sun Feb 25, 2007 2:22 pm

I'm sorry I told you wrong, this is what I am getting.

Here are the values that this example is based on:
S2: 2.646
T1: 120

This gives me a correct value in T5, i.e. 2156
if (document.cMount.S3.value==12){
var Lmax=((2*t)*(146700/3))/y;}

Using the same values as above these two give me (2156 +6) 2162. The correct answer should be 2054.
if (document.cMount.S3.value==25){
var Lmax=((2*t)*(146700/3))/(y+6);}

if (document.cMount.S3.value==64){
var Lmax=((2*t)*(146700/3))/(y+6);}
edp1959
 
Posts: 4
Joined: Sun Feb 25, 2007 12:30 pm

Postby jntcomputers on Sun Feb 25, 2007 3:40 pm

Try creating a third variable like

x = y + 6;

then

var Lmax=((2*t)*(146700/3))/x;

OR

try this

var Lmax=(((2*t)*(146700/3))/(y+6));}

(adding parenthesis around the whle equation...
jntcomputers
 
Posts: 5
Joined: Sun Feb 25, 2007 5:42 am

Please help with calculation

Postby edp1959 on Sun Feb 25, 2007 3:50 pm

var z=y+6

var Lmax=((2*t)*(146700/3))/z;

This gives me T5 = NaN
edp1959
 
Posts: 4
Joined: Sun Feb 25, 2007 12:30 pm


Who is online

Users browsing this forum: No registered users and 6 guests