/    Sign up×
Community /Pin to ProfileBookmark

function script error

Hi, I have writen this script to calculate the difference between two periods of time and enter it into a text box, here is my script

<script>
if amPmOne.toLowerCase = ‘pm’ then hourOne = hourOne +12
if amPmTwo.toLowerCase = ‘pm’ then hourTwo = hourTwo + 12

function calc {if calc.onClick then
finalHours = hourTwo – hourOne
finalMinutes = minuteTwo – minuteOne
finalTime = finalHours + (finalMinutes / 60) }
</script>
<style>
body {margins:0; font-face:arial;}
</style>
<form name=”calc_flight_time”>
<table width=”361″ border=”0″>
<tr>
<td width=”161″><strong>Departed At</strong></td>
<td width=”88″><input name=”hourOne” type=”text” id=”hourOne” size=”5″>
:
<input name=”minuteOne” type=”text” id=”minuteOne” size=”5″></td>
<td width=”137″><select name=”amPmOne”>
<option value=”am”>am</option>
<option value=”pm”>pm</option>
</select></td>
</tr>
<tr>
<td><strong>Arrived At</strong></td>
<td><input name=”hourTwo” type=”text” id=”hourTwo” size=”5″>
:
<input name=”minuteTwo” type=”text” id=”minuteTwo” size=”5″></td>
<td><select name=”amPmTwo” id=”amPmTwo”>
<option value=”am”>am</option>
<option value=”pm”>pm</option>
</select></td>
</tr>
<tr>
<td><input name=”calcflttime” type=”submit” id=”calcflttime” value=”Calculate…” onClick=”javascript(calc)”></td>
<td><input name=”finalHours” type=”text” id=”hourTwo23″ size=”5″>
:
<input name=”finalMinutes” type=”text” id=”finalMinutes” size=”5″></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name=”finalTime” type=”text” id=”hourTwo222″ size=”12″></td>
<td>&nbsp;</td>
</tr>
</table>
<p>&nbsp; </p>
</form>

what am I doing wrong?

Ben

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@PittimannFeb 04.2004 — Hi!

The code below doesn't claim to be complete concerning the time comparison. Just play with it...
[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<style type="text/css">
<!--
body {margins:0; font-face:arial;}
-->
</style>
<script language="JavaScript" type="text/javascript">
<!--
function calc (){
hour1=parseInt(document.calc_flight_time.hourOne.value);
minute1=parseInt(document.calc_flight_time.minuteOne.value);
hour2=parseInt(document.calc_flight_time.hourTwo.value);
minute2=parseInt(document.calc_flight_time.minuteTwo.value);
if (document.calc_flight_time.amPmOne.value == 'pm') hour1 = hour1 +12;
if (document.calc_flight_time.amPmTwo.value == 'pm') hour2 = hour2 + 12;
if (hour2>hour1){
finalHours=hour2 - hour1;
}
else if (hour2==hour1&&minute2==minute1){
finalHours=24;
}
else if (hour2==hour1&&minute2>minute1){
finalHours=0;
}
else{
finalHours=24+hour2 - hour1;
}
if (minute2>minute1){
finalMinutes=minute2 - minute1;
}
else if (minute2==minute1){
finalMinutes=0;
}
else{
finalMinutes=60+minute2 - minute1;
finalHours --;
}
document.calc_flight_time.finalHours.value = finalHours;
document.calc_flight_time.finalMinutes.value = finalMinutes;
document.calc_flight_time.finalTime.value = finalHours + (finalMinutes / 60)
}
//-->
</script>
</head>
<body>
<form name="calc_flight_time">
<table width="361" border="0">
<tr>
<td width="161"><strong>Departed At</strong></td>
<td width="88"><input name="hourOne" type="text" id="hourOne" size="5">
:
<input name="minuteOne" type="text" id="minuteOne" size="5"></td>
<td width="137"><select name="amPmOne">
<option value="am">am</option>
<option value="pm">pm</option>
</select></td>
</tr>
<tr>
<td><strong>Arrived At</strong></td>
<td><input name="hourTwo" type="text" id="hourTwo" size="5">
:
<input name="minuteTwo" type="text" id="minuteTwo" size="5"></td>
<td><select name="amPmTwo" id="amPmTwo">
<option value="am">am</option>
<option value="pm">pm</option>
</select></td>
</tr>
<tr>
<td><input name="calcflttime" type="button" id="calcflttime" value="Calculate..." onClick="calc()"></td>
<td><input name="finalHours" type="text" id="hourTwo23" size="5">
:
<input name="finalMinutes" type="text" id="finalMinutes" size="5"></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input name="finalTime" type="text" id="hourTwo222" size="12"></td>
<td> </td>
</tr>
</table>
<p> </p>
</form>
</body>
</html>
[/code]

Cheers - Pit
×

Success!

Help @benchoffman spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...