Simple Calculation prior to sending form.

5 posts by 3 authors in: Forums > CMS Builder
Last Post: April 11, 2013   (RSS)

By Toledoh - April 8, 2013

Hi All.

I've got a simple emailForm.php that is acting as a booking form. ie.

        <form method="POST" action="">
        <input type="hidden" name="submitForm" value="1" />
        
        
        <?php if (@$errorsAndAlerts): ?>
          <div style="color: red; font-weight: bold; font-size: 16px; font-family: arial;"><br/>
            <?php echo $errorsAndAlerts; ?><br/><br/>
          </div>
        <?php endif ?>
        
        <table border="0" cellspacing="0" cellpadding="2">
         <tr>
          <td width="150">A</td>
          <td><input type="text" name="a" value="<?php echo htmlspecialchars(@$_REQUEST['a']); ?>" size="50" /></td>
         </tr>
         <tr>
          <td width="150">B</td>
          <td><input type="text" name="b" value="<?php echo htmlspecialchars(@$_REQUEST['b']); ?>" size="50" /></td>
         </tr>
        <tr>
          <td width="150">A + B</td>
          <td><input type="text" name="c" value="<?php echo htmlspecialchars(@$_REQUEST['c']); ?>" size="50" /></td>
         </tr>
         <tr>
          <td colspan="2" align="center">
            <br/>
            <input type="submit" name="submit" value="Send Message &gt;&gt;">
          </td>
         </tr>
        </table>
        
        </form>

How can I get the total of A + B to display in C? Prior to submitting the form?

Cheers,

Tim (toledoh.com.au)

By Djulia - April 8, 2013

Hi

I think that you can use Javascript.

An example here:

http://stackoverflow.com/questions/7563879/how-to-calculate-active-total-using-javascript-for-html-form

Hope that helps!

Djulia

By Toledoh - April 9, 2013

Mate - it's brilliant!  Thanks.

Cheers,

Tim (toledoh.com.au)

By Toledoh - April 11, 2013

Hey, that's pretty cool also!  Bookmarked!

Cheers,

Tim (toledoh.com.au)