Forum Moderators: open

Message Too Old, No Replies

so Lost

Ticket cost calculator

         

aaronsmith3

12:07 am on Apr 17, 2011 (gmt 0)

10+ Year Member



Hi everyone. Please be patient with me as I am TOTALLY new to JS and I'm severely lost. I'm trying to do this one section at a time. I have to create a ticket calculator. I have the html done and now I'm onto the fun part :( I first want to create an alert for the quantity text field so that if they enter <=0 || >=10 then it prompts the alert. Then I need to tally a subtotal once they enter a correct quantity and select a section from the drop down menu. THANKS for any and all help.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"/>
<link rel="stylesheet" type="text/css" href="hw5.css" />

<title>HW 5 Tix Calc</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js">



</script>


</head>


<body>
<script tyep="text/javascript">
function validateInput()
{
Quantity=quantity("quantity");
if (Quantity <= "0" || >= "10"){
alert ("Please enter a quantity greater than zero or no more than 10.");
return false;
}else{
return true;
}
}


}
</script>


<h1 class="center">Ticket Cost Calculator</h1>
<form name=frmOrder>
<div>


<table class="table" >
<tr>
<th>Location:</th>
<th>Quantity:</th>
</tr>
<tr>
<td><select name="location" onChange="compute_total()">
<option value="E">End zone $10</option>
<option value="NB">Not bad $20</option>
<option value="G">Good $30</option>
</select>
</td>

<!--enter ticket quantity -->
<td>
<input type="text" value="" name="quantity" maxlength="2" value="" size="9" onChange=validateInput(this.value) />
</td>
</tr>

<tr>
<td>Subtotal:</td>
<td>
<input type="text" name="subtotal" value="" size="9" readonly="readonly" />
</td>
</tr>

<tr>
<td>
<input type="radio" class="radio" name="delivery" value="WC"/>Will Call ($5) or
<p><input type="radio" class="radio" name="delivery" value="OD"/> Overnight Deliver ($15)</p>
</td>
<td>
<input type="text" name="$willcall" value="" size="9" readonly="readonly" onChange="compute_total()"/>
</td>
</tr>



<tr>
<td>Grand Total:</td>
<td>
<input type="text" name="grandtotal" value="" size="9" readonly="readonly"/>
</td>
</tr>

<tr>
<td>
<input type="submit" name="calculate" value="Calculate or Recalculate" onClick="calculate()"/>
</td>

<td>
<input type="reset" name="reset" value="Start Over"/>
</td>
</tr>


</table>
</div>

daveVk

10:25 am on Apr 18, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For starter

you call validateInput(this.value)

the correct way to get Quantity from this.value is

function validateInput( Quantity )
{

Any text could have been entered, you need a number

var N=parseInt( Quantity, 10 ); // 10 for decimal

the test becomes

if ( ( N>0 ) && (N<11) ) { return true; }
else {
alert ...
}

aaronsmith3

3:44 pm on Apr 18, 2011 (gmt 0)

10+ Year Member



I THOUGHT I was on the right track but I have a hard time with variables (mostly keeping track of what goes where). Thank you!