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

Javscript Caculator"If-statement" problem

Javscript Caculator"If-statement" problem

Postby soccer23 on Sun Mar 01, 2009 8:46 pm

Hello,

I am trying to make a calculator for our website, with the following function. What I am trying to do is output a specific text value IF var i = a certain number. how would i do this? Thanks.

function calculate(){
var a = document.getElementById('depth');
var b = document.getElementById('finalwidth');
var c = document.getElementById('width');
var d = document.getElementById('length');
var e = document.getElementById('finallength');
var f = document.getElementById('averagedepth');
var g = document.getElementById('gallons');
var h = document.getElementById('circ');
var i = document.getElementById('gph');
var j = document.getElementById('fallwidth');
var k = document.getElementById('falldepth');
var l = document.getElementById('averagelength');
var m = document.getElementById('averagewidth');
var n = document.getElementById('height');
var o = document.getElementById('height2');
var p = document.getElementById('pipe');
var width = parseFloat(c.value);
var depth = parseFloat(a.value);
var length = parseFloat(d.value);
var height = parseFloat(n.value);
var averagewidth = parseFloat(m.value);
var averagelength = parseFloat(l.value);
var averagedepth = parseFloat(f.value);
var circ = parseFloat(h.value);
var fallwidth = parseFloat(j.value);
var falldepth = parseFloat(k.value);
var gph = parseFloat(i.value);
var pipe = parseFloat(p.value);
b.value = depth*2+width+4;
e.value = depth*2+length+4;
g.value = averagewidth*averagelength*averagedepth*7.48;
h.value = averagewidth*averagelength*averagedepth*7.48/2;
i.value = falldepth*fallwidth;
o.value = pipe*0.05+height;

}
soccer23
 
Posts: 1
Joined: Sun Mar 01, 2009 8:35 pm

Re: Javscript Caculator"If-statement" problem

Postby rangana on Wed Mar 04, 2009 6:38 am

You should note that your "var i" references to the element with the id of gph.

It doesn't have any value, (not unless you'll use .value namespace).

Hope that makes sense, but if you would like to use an "if()" statement, the format is this:
Code: Select all
if (i=='a certain value')
// alert('Whatever here');
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines


Who is online

Users browsing this forum: No registered users and 4 guests