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
    Jan 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Multiplying Form Fields

    I am working on the form below.
    I want to add together the #'s from the Girls and Adults field then multiply that # by the Hours field and have the total placed in the Total Hours Given field.

    Ex.
    Girls = 2
    Adults = 5
    Hours = 10
    Total HoursGiven = 20

    Then I want to take the Total Hours Given # and add it to the #'s in the Girl Hours and Adult Hours fields and have that # placed in the New Total # of hours given field.

    Ex.
    Total Hours Given = 20
    Girls Hours = 5
    Adult Hours = 5
    New Total # of hours given = 30

    I have started working with the first part but can't get the multiplication to work. I was wondering if someone could take a look and tell me what I am doing wrong.


    Code:
    <html>
    <head>
    
    <script type="text/javascript">
    
    //Calulate Total
    function startTotal(){
      interval = setInterval("calcTotal()",1);
    }
    function calcTotal(){
      var g1girl = document.sog.g1GirlPar1.value;
      var g1adult = document.sog.g1AdultPar1.value; 
      var g1hours = document.sog.g1HoursServed1.value; 
      document.sog.g1HoursGiven1.value = (g1girl * 1) + (g1adult * 1) * (g1hours * 1);
      
    }
    function stopTotal(){
      clearInterval(interval);
    }
    
    
    </script>
    
    </head>
    <body>
    
    
    
    
    			
    <form name="sog" method="post" action="send.asp" >
    <table width="500" border="0" cellpadding="3" cellspacing="0" bgcolor="#000000" class="main">
        
                      
                      <tr valign="top" bgcolor="#FFFFFF" class="main"> 
                        <td>Girls:</td>
                        <td align="left"><input name="g1GirlPar1" type="text" size="5" value="" class="shadowSm" onFocus="startTotal();" onBlur="stopTotal();"></td>
                      </tr>
                      
                      
                      <tr valign="top" bgcolor="#FFFFFF" class="main"> 
                        <td>Adults:</td>
                        <td align="left"><input name="g1AdultPar1" type="text" size="5" value="" class="shadowSm" onFocus="startTotal();" onBlur="stopTotal();"> </td>
                      </tr>
    
    
                      <tr valign="top" bgcolor="#FFFFFF" class="main"> 
                        <td>Hours:</td>
                        <td align="left"><input name="g1HoursServed1" type="text" size="5" value="" class="shadowSm" onFocus="startTotal();" onBlur="stopTotal();"> </td>
                      </tr>
    
                      <tr valign="top" bgcolor="#FFFFFF" class="main"> 
                        <td>Total Hours Given:</td>
                        <td align="left">
                        
                        <input name="g1HoursGiven1" type="text" size="5" value="" class="shadowSm"> Girls + Adults x Hours
                        
        
                         </td>
                      </tr>
                      
    				  
                      <tr valign="top" bgcolor="#FFFFFF" class="main"> 
                        <td>Girl Hours:</td>
                        <td align="left"><input name="g1GirlHours1" type="text" size="5" value="" class="shadowSm"> </td>
                      </tr>				  
    				  
                      <tr valign="top" bgcolor="#FFFFFF" class="main"> 
                        <td>Adult Hours:</td>
                        <td align="left"><input name="g1AdultHours1" type="text" size="5" value="" class="shadowSm"> </td>
                      </tr>				  
    		
            
                       <tr valign="top" bgcolor="#FFFFFF" class="main"> 
                        <td>New Total # of hours given:</td>
                        <td align="left">
                        <input name="g1Hours1" type="text" size="5" value="" class="shadowSm"> Total Hours Given + Girl Hours + Adult Hours
             </td>
                      </tr>
                      
    
                      
                      
                      
                      <tr valign="top" bgcolor="#FFFFFF" class="main">
                        <td><input type="submit" value="Submit" class="xml-icon"></td>
                        <td align="left">&nbsp;</td>
                      </tr>
                    </table>
    
    </form>
    
     
    </body>
    </html>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,731
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Code:
      document.sog.g1HoursGiven1.value = ((g1girl * 1) + (g1adult * 1)) * (g1hours * 1);

    Quizmaster: In Roman Catholicism, baptism, confirmation and matrimony are three of the seven what?
    Contestant: Deadly sins.

  • Users who have thanked Philip M for this post:

    slash75 (01-16-2009)

  • #3
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Of course that is the one thing I didn't think of! Thank you.


  •  

    Posting Permissions

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