View Single Post
Old 01-25-2013, 03:10 AM   PM User | #15
andynov123
Regular Coder

 
Join Date: Oct 2010
Posts: 246
Thanks: 8
Thanked 1 Time in 1 Post
andynov123 is an unknown quantity at this point
Quote:
Originally Posted by Philip M View Post
You code is still rotten with errors.

One more time: You changed all of the getElements to name'Ticket' without changing the corresponding input names/ids.
input Id="adult"

If you used Number() as I advised then 2+3 comes to 5, not 23 which is two string values concatenated. I don't think that the code you posted here is the same code as you are using to test.

To multiply the number of tickets by price simply do

var Adult = Number(document.getElementById('adultTicket').value) || 0;
var aduitprice = 10.50; // (no $ sign!!)
var adultcost = Adult * adultprice;

If desired add a $ sign to the total at the end before displaying the result.
I think I fixed everything you are talking about but something is now keeping my calculate now button from working. Nothing appears.

Code:
<html>

<head>
<title>AMC Ticket Calculator</title>




<style type="text/css">
#welcome{color:red;font-size:35px;font-family:impact;}
body{border-style:solid;overflow:hidden;border-color:red;
border-width:20px;}
#please{font-size:20px;color:red;font-weight:bold;}
#please1{font-size:20px;color:red;font-weight:bold;}
#please2{font-size:20px;color:red;font-weight:bold;}
#logo
{
float:right;margin-top:-45px;margin-right:200px;
}
#info
{
	
	font-weight:bold;
	margin-top:10px;
font-size:15px;	
}
#ticketType{margin-left:30px;float:left;font-size:25px;}
#qty{margin-top:11px;font-size:25px;margin-right:110px;}
#price{margin-right:30px;float:right;font-size:25px;margin-top:-28px;}
#additionalCharge
{
position:relative;left:20px;
}
#clear{
	margin-top:330px;
	
	}
#calculate{
border-style:solid;border-color:red;width:600px;height:450px;float:right;margin-top:-470px;margin-right:20px;text-align:center;color:red;font-weight:bold;font-size:35px;}



</style>
</head>
<body>
<center><div id="welcome">Welcome to the <img src
="https://si0.twimg.com/profile_images/2391543757/ar8n1bu3oc6mo4am5ef1_normal.jpeg" alt="logo"/>Ticket Calculator</div></center>	


<form>

<div id="please">Please enter what time frame the movie is in:</div>
<input Id="beforenoon" type="radio" name="showtype"
value="beforenoon">Before 12 P.M.<br>
<input Id="twelvetofour" type="radio" name="showtype"
value="twelvetofour">Between 12 P.M. and 4 P.M.<br>
<input Id="afterfour" type="radio" name="showtype"
value="afterfour">After 4 P.M.<br><br>








<div id="please1">Please enter the quantity of each ticket</div>
Please leave blank any that do not apply<br>


<input Id="adultTicket" type="text" size="1" name="adult" >Adult<br>
<input Id="childTicket" type="text" size="1" name="child" >Child<br>
<input Id="seniorTicket" type="text" size="1" name="senior" >Senior<br>
<input Id="militaryTicket" type="text" size="1" name="military" >Military<br>
<input Id="seniordayTicket" type="text" size="1"
name="seniorday" >Senior Day Ticket<br>
<input Id="studentdayTicket" type="text" size="1"
name="studentday" >Student Day Ticket<br>
<br>
<div id="please2">Please enter additional information if needed</div>
<input Id="threed"
type="text" size="1" name="quantity" >How many tickets are regular<b> 3D?</b>($3.50 additional charge perticket)<br>
<input Id="imax"type="text" size="1" name="quantity" >How many tickets are <b>IMAX(NO 3D)?</b>($4.50 additional charge per
ticket)<br>
<input Id="imax3d" type="text"
size="1" name="quantity" >How many tickets are <b>IMAX 3D?</b>($5.50 additional charge per ticket)<br>



<br>
<input type="button" onclick="displayTotal()" value="Calculate Now!">


</form>

<div id="calculate">
Total Breakdown

<br>
<div id="info"><div id="ticketType">Ticket Type</div><div id="qty">Quantity</div><div id="price">Price</div></div>
<div id="clear"><input type="button" value="Clear Everything and Start Over" onclick="document.location.reload(true)">
</div>

</div>

</div>
<script type="text/javascript">




function displayTotal(){


var senior = document.getElementById('seniorTicket').value;
var military = document.getElementById('militaryTicket').value;
var senior = Number(document.getElementById('seniorTicket').value) || 0;
var seniorprice = 9.50; // (no $ sign!!)
var seniorcost = Senior * seniorPrice;
var Military = Number(document.getElementById('militaryTicket').value) || 0;
var militaryprice = 9.00; // (no $ sign!!)
var militarycost = Military * militaryprice;
var StudentDay = Number(document.getElementById('studentDayTicket').value) || 0;
var studentdayprice = 7.50; // (no $ sign!!)
var studentdaycost = StudentDay * studentdayprice;
var Adult = Number(document.getElementById('adultTicket').value) || 0;
var aduitprice = 10.50; // (no $ sign!!)
var adultcost = Adult * adultprice;
var Child = Number(document.getElementById('childTicket').value) || 0;
var childprice = 7.50; // (no $ sign!!)
var childcost = child * childprice;
var total = childcost+adultcost;
prompt("The total is " + total);
}


</script>
</body>



</html>
andynov123 is offline   Reply With Quote