/    Sign up×
Community /Pin to ProfileBookmark

Please Help With Calculation

I am new to Javascript, but am trying to do a simple calculation. I need to have the rate that is displayed by the ATHLETE option box, multiplied by the number of hours, displayed in the price box below once the button is clicked. I am very close but must be slightly off. If someone could please help it would be greatly appreciated. Reply here or email me at [email][email protected][/email] Thanks Again.

<html>
<title>Book The Brits Now!</title>
<head>
<SCRIPT LANGUAGE=”JAVASCRIPT”>
<!–Hide from old browsers
document.bgColor=”gold”
var athlete= new Array(0, 19, 39, 79)
function Calc(myForm) {
var athleteItem = myForm.athlete.selectedIndex
var totalPrice = athlete[athleteItem]
document.XOptions.ratea.value = format(totalPrice)
}

function Price(myForm) {
var athleteItem = myForm.athlete.selectedIndex
var hourNum = myForm.hoursa.value
var EstPrice = hourNum*athleteItem
document.ZOptions.PicExtPrice.value = format(EstPrice)
}
//–>
</SCRIPT>
</head>
<body text=”black” link=”red” vlink=”red” onload=”setTimeout(‘bancycle()’,3000)” align=”center”>
<SCRIPT LANGUAGE=”JAVASCRIPT”>
<!– Hide from old browsers
function format(valuein) {
var dollars = new String(valuein)
var Outdollars = ” “
var dollen = dollars.length
if (dollen > 3) {
while (dollen>0) {
tDollars=dollars.substring(dollen-3, dollen)
if (tDollars.length==3) {
Outdollars=”,”+tDollars+Outdollars
dollen=dollen-3;
} else {
Outdollars=tDollars+Outdollars
dollen=0
}
}
if (Outdollars.substring(0, 1)==”,”)
dollars=Outdollars.substring(1, Outdollars.length)
else
dollars=Outdollars
}
var amountOut = “$”+dollars
return amountOut
}
// — End hiding here –>
</SCRIPT>
<h1 align=”center”>Book The Brits!</H1>
<CENTER><IMG SRC=”chris.jpg”>
<CENTER><TABLE BORDER=0 WIDTH=”60%”>

<TR>
<TD COLSPAN=”3″>The Brits want to come and play for you, so fill in the form below and we will be glad to bring you a wonderful performance! The base price for a one hour performance is $99, but with the additional information you will provide below we will determine the actual cost. All prices below are based on an hourly rate.
<P><B>Optional Upgrades</B></td>
<tr>
<td><FORM NAME=”XOptions”>
<SELECT Name=”athlete” onchange=”Calc(XOptions)”>
<OPTION>Select Athlete Options
<OPTION>Basic Set-up
<OPTION>Full Light Show
<OPTION>Full Light Show with Video Screen
</SELECT>
</td>
<td>
<BR>
<SELECT Name=”embrace”>
<OPTION>Select Embrace Options
<OPTION>Basic Set-up
<OPTION>Full Light Show
<OPTION>Full Light Show with Video Screen
</SELECT>
<BR>
</td>
<td>
<SELECT Name=”coldplay”>
<OPTION>Select Coldplay Options
<OPTION>Basic Set-up
<OPTION>Full Light Show
<OPTION>Full Light Show with Video Screen
</SELECT>
</td>
</tr>
<tr>
<td><p align=”left”>Rate: <Input Type=”text” Name=”ratea” value=” “></td>
<td><p align=”left”>Rate: <Input Type=”text” Name=”ratee” value=” “></td>
<td><p align=”left”>Rate: <Input Type=”text” Name=”ratec” value=” “></td>
</tr>
<tr>
<td><p align=”left”>Hours: <Input Type=”text” Name=”hoursa” value=”3″></td>
<td><p align=”left”>Hours: <Input Type=”text” Name=”hourse” value=” “></td>
<td><p align=”left”>Hours: <Input Type=”text” Name=”hoursc” value=” “></td>
</tr>
</form>
<tr>
<td><FORM NAME=”ZOptions”>
<P>Calculated price: <INPUT type=”text” value=” ” Name=”PicExtPrice” size=7>
<P><INPUT type=”Button” value=”Price” onchange=”Price()” Name=”Arrangement”></TD>
<td>
<P>Calculated price: <INPUT type=”text” value=” ” Name=”PiecePrice” size=7>
<P><INPUT type=”Button” value=”Price” onclick=”Calc(XOptions)” Name=”Arrangement”></TD>
<td>
<P>Calculated price: <INPUT type=”text” value=” ” Name=”PiecePrice” size=7>
<P><INPUT type=”Button” value=”Price” onclick=”Calc(XOptions)” Name=”Arrangement”></TD>
</tr>
</FORM>
</TABLE></CENTER>

</body>

</html>

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@JuuitchanFeb 14.2005 — This line is wrong:

var EstPrice = hourNum*athleteItem

I think it should be:

var EstPrice = hourNum*athlete[athleteItem]

but I don't have time to check further.
Copy linkTweet thisAlerts:
@kornkob_73authorFeb 14.2005 — Thanks for the help, although I did try that and it is still not working. Does anyone else know?
Copy linkTweet thisAlerts:
@VinceFeb 14.2005 — Hi kornkob_73

I have a slightly simpler way to make your calculation.

<i>
</i>&lt;html&gt;
&lt;head&gt;
&lt;Script type="text/javascript"&gt;
&lt;!--
function calcPrice(){
var intCost = document.getElementById("athlete").value
var intHours = document.getElementById("hoursa").value
document.getElementById("Total").innerText = intCost * intHours
}
--&gt;
&lt;/Script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;SELECT id="athlete" Name="athlete" onchange=""&gt;
&lt;OPTION value="0"&gt;Select Athlete Options&lt;/option&gt;
&lt;OPTION value="19"&gt;Basic Set-up&lt;/option&gt;
&lt;OPTION value="39"&gt;Full Light Show&lt;/option&gt;
&lt;OPTION value="79"&gt;Full Light Show with Video Screen&lt;/option&gt;
&lt;/SELECT&gt;&lt;br&gt;

&lt;label for="hoursa" align="left"&gt;Hours: &lt;Input id="hoursa" Type="text" Name="hoursa" value="3"&gt;&lt;br&gt;
&lt;p&gt;The Total is $ &lt;span id="Total"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;INPUT type="Button" value="Calculate" onclick="calcPrice()" Name="Arrangement"&gt;
&lt;/body&gt;
&lt;/html&gt;


I am sure that you will be able to figure it out

Regards V
Copy linkTweet thisAlerts:
@Warren86Feb 14.2005 — <html>

<title>Book The Brits Now!</title>

<head>

<SCRIPT LANGUAGE="JAVASCRIPT">

var isForm = "";
var isAthlete = "";
var isEmbrace = "";
var isColdPlay = "";

function calcForm(isField){

athleteVal = isAthlete.value;
embraceVal = isEmbrace.value;
coldPlayVal = isColdPlay.value;
basePrice = parseFloat(99);
athleteHours = isForm.hoursa.value;
embraceHours = isForm.hourse.value;
coldPlayHours = isForm.hoursc.value;
isForm.ratea.value = athleteVal;
isForm.ratee.value = embraceVal;
isForm.ratec.value = coldPlayVal;
isValid = true;
if (isNaN(athleteHours) || isNaN(embraceHours) || isNaN(coldPlayHours))
{isValid = false; isField.value=""}
if (isValid)
{
athleteOption = parseFloat(athleteVal)*parseFloat(athleteHours);
embraceOption = parseFloat(embraceVal)*parseFloat(embraceHours);
coldPlayOption = parseFloat(coldPlayVal)*parseFloat(coldPlayHours);
isSum = athleteOption+embraceOption+coldPlayOption+basePrice;
if (isNaN(isSum)){isForm.totalPrice.value = '---'};
else {isForm.totalPrice.value = isSum.toFixed(2)};
}
}

function init(){

document.bgColor="gold";
isForm = document.forms['XOptions']
isAthlete = document.getElementById('athlete');
isEmbrace = document.getElementById('embrace');
isColdPlay = document.getElementById('coldplay');
hourFields = document.getElementsByTagName('INPUT');
for (i=0; i<hourFields.length-1; i++)
{hourFields[i].onclick = function(){this.value="";calcForm()}}
}

window.onload=init;


</SCRIPT>

</head>

<body text="black" link="red" vlink="red" align="center">

<h1 align="center">Book The Brits!</H1>

<CENTER><IMG SRC="chris.jpg">

<CENTER><TABLE BORDER=0 WIDTH="60%">

<TR>

<TD COLSPAN="3">The Brits want to come and play for you, so fill in the form below and we will be glad to bring you a wonderful performance! The base price for a one hour performance is $99, but with the additional information you will provide below we will determine the actual cost. All prices below are based on an hourly rate.

<P><B>Optional Upgrades</B></td>

<tr>

<td>

<FORM NAME="XOptions">

<SELECT id="athlete" onchange="calcForm()">

<OPTION value='0'>Select Athlete Options

<OPTION value='19.00'>Basic Set-up

<OPTION value='36.00'>Full Light Show

<OPTION value='86.00'>Full Light Show with Video Screen

</SELECT>

</td>

<td>

<BR>

<SELECT id="embrace" onchange="calcForm()">

<OPTION value='0'>Select Embrace Options

<OPTION value='28.75'>Basic Set-up

<OPTION value='39.25'>Full Light Show

<OPTION value='49.95'>Full Light Show with Video Screen

</SELECT>

<BR>

</td>

<td>

<SELECT id="coldplay" onchange="calcForm()">

<OPTION value='0'>Select Coldplay Options

<OPTION value='30.00'>Basic Set-up

<OPTION value='42.59'>Full Light Show

<OPTION value='56.89'>Full Light Show with Video Screen

</SELECT>

</td>

</tr>

<tr>

<td><p align="left">Rate: &pound&nbsp<Input Type="text" name="ratea" size='6' readonly value="0" onchange="calcForm(this)"></td>

<td><p align="left">Rate: &pound&nbsp<Input Type="text" name="ratee" size='6' readonly value="0" onchange="calcForm(this)"> </td>

<td><p align="left">Rate: &pound&nbsp<Input Type="text" name="ratec" size='6' readonly value="0" onchange="calcForm(this)"></td>

</tr>

<tr>

<td><p align="left">Hours: <Input Type="text" name="hoursa" size='6' value="0" onkeyup="calcForm(this)"></td>

<td><p align="left">Hours: <Input Type="text" name="hourse" size='6' value="0" onkeyup="calcForm(this)"></td>

<td><p align="left">Hours: <Input Type="text" name="hoursc" size='6' value="0" onkeyup="calcForm(this)"></td>

</tr>

<TR>

<TD>Total Price:&nbsp;&pound;&nbsp<input type=text name='totalPrice' size='7' value="99.00" readonly></TD>

</TR>

</form>

</TABLE></CENTER>

</body>

</html>
Copy linkTweet thisAlerts:
@kornkob_73authorFeb 15.2005 — thanks to you both!!!
×

Success!

Help @kornkob_73 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,
)...