...

View Full Version : Javascript Not mulitplying values



shortkid422
12-31-2003, 02:18 AM
Ok, i still havent figured out javascript yet, lol. Anyways, i want to multiply the values from the form and the add them together to give a total price. Here is my code:


<p align="center">Purchase Rooms For The <? echo "$name In $city, $country"; ?></p>
<form action="calculate.php" method="post">
<table align="center">
<tr>
<td>Title:</td><td>
<select name='credit_card_type'>
<option value="Mr.">Mr.</option>
<option value="Mrs.">Mrs.</option>
<option value="Ms.">Ms.</option>
</select></td>
</tr>
<tr>
<td>First Name:</td><td><input type="text" name="first_name"></td>
</tr>
<tr>
<td>Last Name:</td><td><input type="text" name="last_name"></td>
</tr>
<tr>
<td>Address Line 1:</td><td><input type="text" name="address_1"></td>
</tr>
<tr>
<td>Address Line 2:</td><td><input type="text" name="address_2"></td>
</tr>
<tr>
<td>City/Town:</td><td><input type="text" name="town"></td>
</tr>
<tr>
<td>Home Phone Number:</td><td>(<input type="text" name="phone_area_code" size="4" maxlength="4" value="">)-<input type="text" name="phone_number_1" size="3" maxlength="3" value="">-<input type="text" name="phone_number_2" size="4" maxlength="4" value=""></td>
</tr>
<tr>
<td>Work Phone Number:</td><td>(<input type="text" name="work_area_code" size="4" maxlength="4" value="">)-<input type="text" name="work_number_1" size="3" maxlength="3" value="">-<input type="text" name="work_number_2" size="4" maxlength="4" value=""></td>
</tr>
<tr>
<td>Mobile Phone Number:</td><td>(<input type="text" name="mobile_area_code" size="5" maxlength="5" value="">)-<input type="text" name="mobile_number_1" size="3" maxlength="3" value="">-<input type="text" name="mobile_number_2" size="3" maxlength="3" value=""></td>
</tr>
<tr>
<td>Email:</td><td><input type="text" name="email"></td>
</tr>
<tr>
<td>Postcode:</td><td><input type="text" name="postcode_1" size="4" maxlength="4">-<input type="text" name="postcode_2" size="3" maxlength="3"></td>
</tr>
<tr><td>Room Type:</td><td>
<select name='room'>
<option value="single_room">Single Room (<? echo "$single_room"; ?>/adult)</option>
<option value="double_room">Double Room (<? echo "$double_room"; ?>/adult)</option>
</select></td></tr>
<tr>
<td>Number of Adults (13+ years):</td><td><input type="text" name="adult_number" size="2" maxlength="2"></td>
</tr>
<tr>
<td>Number of Children (3-12 years):</td><td><input type="text" name="children_number" size="2" maxlength="2"></td>
</tr>
<tr>
<td>Number of Infants (0-2 years):</td><td><input type="text" name="infant_number" size="2" maxlength="2"></td>
</tr>
<tr>
<td>Credit Card Company:</td><td>
<select name='credit_card_type'>
<option value="American Express">American Express</option>
<option value="Delta">Delta</option>
<option value="Master Card">Master Card</option>
<option value="Solo">Solo</option>
<option value="Visa">Visa</option>
</select></td>
</tr>
<tr>
<td>Credit Card Number:</td><td><input type="text" name="credit_card_1" size="4" maxlength="4">-<input type="text" name="credit_card_2" size="4" maxlength="4">-<input type="text" name="credit_card_3" size="4" maxlength="4">-<input type="text" name="credit_card_4" size="4" maxlength="4"></td>
</tr>
<tr>
<td><input type="submit" value="Purchase"></td><td><input type="reset" value="Clear"></td>
</tr>
</table>
</form>
?>
my processor for this is the javascript part:


<script language="javascript">
if (document.hotel_process.room.options['single_room'].selected) {
<? $adult_price = $_POST['adult_number'] * $_POST['single_room']; ?>
<? $children_price = $_POST['children_number'] * $_POST['single_room']; ?>
<? $total_price = $children_price + $adult_price ?>
}
if (document.hotel_process.room.options['double_room'].selected) {
<? $adult_price = $_POST['adult_number'] * $_POST['double_room']; ?>
<? $children_price = $_POST['children_number'] * $_POST['double_room']; ?>
<? $total_price = $children_price + $adult_price ?>
}
</script>
<?
echo "$total_price";
?>

Oakendin
12-31-2003, 05:00 AM
It would be more helpful if you posted the generated HTML code.

shortkid422
12-31-2003, 06:52 PM
it just returns 0



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum