PDA

View Full Version : [RESOLVED] JavaScript Fishing Calculator Help


rhd
09-14-2008, 11:16 PM
Hi,

I am working on building a web site that promotes fishing, one of the things I would like to include on the site is a calculator that determines the amount of time (days, weeks, months and years) you have to fish based on a given life expectancy.

I have the basic source for the calculator laid out from looking around the web at different JavaScript calculators, I am really struggling with the end calculations for the days, weeks, months and years based on the users input, I would also like to the user to be able to choose from a pull down option the "life EXPECTANCY" input.

If someone could help me with this or point me in the right direction, I would be eternally grateful.

Right now, the JavaScript is calculating a different calculation than the ones I want.

What I need is to generate the Age of the person, based on that it could calculate the days, weeks, months and years based on the life expectancy input.

Thanks for your time.

-rhd

Do not forget to go FISHING when ever possible! :D


<html>
<head>
<title>GO FISHING Before it's too late!</title>
</head>

<table width="796" height="35" border="0" align="center" cellpadding="0" cellspacing="0" class="">

<td width="606" valign="top" class="maintd"><h1 align="center"><font face="Tahoma" size="7">FISH Before it's too late!</font> </h1>

<p align="center">"GOD does not deduct from man's allotted span the hours and days spent in fishing."</p>

<script language="JavaScript">

function fish_calc()
{
// User Input
var d = parseInt(document.getElementById('day').value);
var m = parseInt(document.getElementById('month').value);
var y = parseInt(document.getElementById('year').value);
var E = parseInt(document.getElementById('expected').value);

// Start Date
var starto = new Date();
starto.setDate(d);
starto.setMonth(m-1);
starto.setYear(y);
var daymsecs = 60*60*24*1000;
starto.setTime(starto.getTime() + ((E * daymsecs) - daymsecs*14));

// Time Left
document.getElementById('DAYS').value = formatted_date(starto);
var age = new Date();
age.setTime(starto.getTime() + daymsecs*266);
document.getElementById('DAYS').value = formatted_date(age);
starto.setTime(starto.getTime() + daymsecs*70);
document.getElementById('WEEKS').value = formatted_date(starto);
starto.setTime(starto.getTime() + daymsecs*105);
document.getElementById('MONTHS').value = formatted_date(starto);
starto.setTime(starto.getTime() + daymsecs*105);
document.getElementById('YEARS').value = formatted_date(starto);
}

function formatted_date(date)
{
var month = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October",
"November", "December");
var y = date.getYear()+1900;
if ((y > 100) && (y <1900)) y+=1900;
if (y == 3900) y = 2000;
return("" + month[date.getMonth()] + " " + date.getDate() + ", " + y);
}

</script>

<form name="calculator">

<table width="570" border="0" align="center" cellpadding="4" cellspacing="2" class="border">
<tr valign="center" bgcolor="#1a397a">
<th scope="col" colspan="2"><h2 class="style1"><font face="Tahoma"><font color="#FFFFFF">The FISHING TIME Calculator</font></font> </h2></th>
</tr>
<tr bgcolor="#f2f7fb">
<th scope="row" colspan="2"><p class="normal"><font face="Tahoma">Enter*Your*DATE OF BIRTH</font>
* </p></th>
</tr>
<tr bgcolor="#f2f7fb">

<th scope="row" colspan="2"><select id="month">
<option value="1" selected="">January
<option value="2">February
<option value="3">March
<option value="4">April
<option value="5">May
<option value="6">June
<option value="7">July
<option value="8">August
<option value="9">September
<option value="10">October
<option value="11">November
<option value="12">December</option>
</select> *

<select id="day">
<option value="1" selected="">1
<option value="2">2
<option value="3">3
<option value="4">4
<option value="5">5
<option value="6">6
<option value="7">7
<option value="8">8
<option value="9">9
<option value="10">10
<option value="11">11
<option value="12">12
<option value="13">13
<option value="14">14
<option value="15">15
<option value="16">16
<option value="17">17
<option value="18">18
<option value="19">19
<option value="20">20
<option value="21">21
<option value="22">22
<option value="23">23
<option value="24">24
<option value="25">25
<option value="26">26
<option value="27">27
<option value="28">28
<option value="29">29
<option value="30">30
<option value="31">31</option>
</select>
*
<select id="year">
<option value="50">1950
<option value="51">1951
<option value="52">1952
<option value="53">1953
<option value="54">1954
<option value="55">1955
<option value="56">1956
<option value="57">1957
<option value="58">1958
<option value="59">1959
<option value="60">1960
<option value="61">1961
<option value="62">1962
<option value="63">1963
<option value="64">1964
<option value="65">1965
<option value="66">1966
<option value="67">1967
<option value="68">1968
<option value="69">1969
<option value="70">1970
<option value="71">1971
<option value="72">1972
<option value="73">1973
<option value="74">1974
<option value="75">1975
<option value="76">1976
<option value="77">1977
<option value="78">1978
<option value="79">1979
<option value="80">1980
<option value="81">1981
<option value="82">1982
<option value="83">1983
<option value="84">1984
<option value="85">1985
<option value="86">1986
<option value="87">1987
<option value="88">1988
<option value="89">1989
<option value="90">1990
<option value="91">1991
<option value="92">1992
<option value="93">1993
<option value="94">1994
<option value="95">1995
<option value="96">1996
<option value="97">1997
<option value="98">1998
<option value="99">1999
<option value="100" selected="">2000
<option value="101">2001
<option value="102">2002
<option value="103">2003
<option value="104">2004
<option value="105">2005
<option value="106">2006
<option value="107">2007
<option value="108">2008
<option value="109">2009
<option value="110">2010
<option value="111">2011
<option value="112">2012
<option value="113">2013
<option value="114">2014
<option value="115">2015
</select></th>

</tr>
<tr bgcolor="#f2f7fb">
<th scope="row"><font face="Tahoma">What is your life EXPECTANCY?*(In Years)</font> * </th>
<td><input type="input" id="expected" value="" style="WIDTH: 33px; HEIGHT: 22px" size="4"></td>
</tr>
<tr bgcolor="#f2f7fb">
<th scope="row" colspan="2"><input type="button" value="Calculate" onclick="fish_calc()"></th>
</tr>

<tr bgcolor="#ece9d8">
<th scope="row"><div align="left">Your Age: </div></th>
<td><input id="AGE" style="BACKGROUND-COLOR: #ece9d8" size="24"></td>
</tr>
<tr bgcolor="#ece9d8">
<th scope="row"><div align="left">Days left to Fish: </div></th>
<td><input id="DAYS" style="BACKGROUND-COLOR: #ece9d8" size="24"></td>
</tr>
<tr bgcolor="#ece9d8">
<th scope="row"><div align="left">Weeks left to Fish: </div></th>
<td><input id="WEEKS" style="BACKGROUND-COLOR: #ece9d8" size="24"></td>
</tr>
<tr bgcolor="#ece9d8">
<th scope="row"><div align="left">Months left to Fish: </div></th>
<td><input id="MONTHS" style="BACKGROUND-COLOR: #ece9d8" size="24"></td>
</tr>
<tr bgcolor="#ece9d8">
<th scope="row"><div align="left" class="orange">Years left to Fish: </div></th>
<td><input id="YEARS" style="BACKGROUND-COLOR: #ece9d8" size="24"></td>
</tr>

</table>
</form>

</td>
</tr>
</table>

</body>
</html>