Hello, I've been a PHP programmer for a number of years and have just
started to learn JS. My Employer (a water analysis lab) wants what
should be a very simple .js written that basically takes sample hold
time data from EPA regulations and spits out when a sample would
expire, so we can properly label the thing.
The problem is that the .js I have written appears to be doing
something unexpected.
The Analysis options are presented as check boxes to the user, and
whichever analysis has the shortest holding time is the one we base
our maximum holding time on.
Here is a snip of the HTML...
<SNIP>
<form method="post" action="" name="Analysis">
<table>
<tr>
<td colspan="2">Sample ID:</td><td><input maxlength=30
name="ID"></td>
</tr>
<tr>
<td>Analyis: (Check All That Apply)</td>
</tr>
<tr>
<td>
<input type="checkbox" name="METALS" >Metals (except Hg)<br>
<input type="checkbox" name="Hg" >Mercury (Hg)<br>
<input type="checkbox" name="ALK" >Alkalinity<br>
<input type="checkbox" name="H3N" >Ammonia<br>
<input type="Submit" onClick=Calc(Analysis) value="Calculate Hold
Times" >
</td>
</tr>
</table>
</form>
</SNIP>
And here is the .js
<SNIP>
function Calc(Analysis){
MyTime = new Date();
checkDate(Analysis,MyTime);
//alert("checkDate cleared success!"+ MyTime);
alert("The expiration of the holding time for sample will occur
"+MyTime);
return;
}
function checkDate(Analysis,MyTime){
alert("checkDate function called");
if(Analysis.RSDI || Analysis.pH){
alert("Entered if statement 1"+ MyTime);
MyTime.setHours(MyTime.getHours()+1);
return MyTime;
}
if(Analysis.ODOR){
alert("Entered if statement 2");
MyTime.setDate(MyTime.getDate()+1);
return;
}
</SNIP>
The problem is that it keeps entering the first if statement which
should only evaluate as true if pH or Residual Disinfectants is
checked. At which time it adds 1 to the hour field and then exits.
This seems VERY counter-intuitive.
I have manually added alerts to check for this behavior, but as you
can see, if you run the sample it just enters the first IF as though
it were true and then completely skips anything after the return
MyTime function.
Any Ideas on what may be wrong here?
Thanks in Advance!
p.s. I'm not sure if this makes a difference for our purposes or not,
it doesn't appear to, but anyways the .js is all contained between
HEAD tags.