Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2003
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript Not mulitplying values

    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:
    PHP 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:
    Code:
    <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";
    ?>

  • #2
    New Coder
    Join Date
    Jul 2002
    Location
    Los Angeles
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It would be more helpful if you posted the generated HTML code.

  • #3
    New to the CF scene
    Join Date
    Nov 2003
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it just returns 0


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •