-1

I have created a simple form that i would like to act as a web calculator where the total would be the sum of the inserted values in the coloums as per the fiddle. How can I achieve so that i can actually calculate with form?

Hmtl:

<h1> Calculator</h1>

<b>Step 1:</b>&nbsp;&nbsp;Click the "Calculate" button to find your purchase cost.
<br>
<b>Step 2:</b>&nbsp;&nbsp;Print this page for your records.
<br>
<p class="margin_top">
<input type="submit" value="Calculate">
<table cellpadding="1" cellspacing="0" border="0">
    <tr>
        <td class="header">Item</td>
        <td class="header"></td>
        <td class="header">Include</td>
        <td class="header"></td>
        <td class="header"></td>
        <td class="header">Actual Amount</td>
        <td class="header"></td>
    </tr>
    <tr>
        <td valign="middle">Facility Rental</td>
        <td></td>
        <td valign="middle" align="center">
            <input type="checkbox" name="item0" value="6" unchecked>
        </td>
        <td></td>
        <td valign="middle">$</td>
        <td valign="middle" align="left">
            <input type="text" name="Ramount[]" value="" size="10">
        </td>
        <td></td>
        <td valign="middle" align="left">$ 0</td>
    </tr>
    <tr>
        <td valign="middle">Officiant</td>
        <td></td>
        <td valign="middle" align="center">
            <input type="checkbox" name="item1" value="1" unchecked>
        </td>
        <td></td>
        <td valign="middle">$</td>
        <td valign="middle" align="left">
            <input type="text" name="Ramount[]" value="" size="10">
        </td>
        <td></td>
        <td valign="middle" align="left">$ 0</td>
    </tr>
    <tr>
        <td align="right">Total:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
        <td></td>
        <td>$ 0</td>
    </tr>

PHP:

<?php
if (isset($_POST['item0'])) $item0 = $_POST['item0'];
if (isset($_POST['item1'])) $item1 = $_POST['item1'];
if (isset($_POST['valuec'])) $valuec = $_POST['valuec'];
$answer = $valuea + $valueb;
user2725936
  • 493
  • 4
  • 9
  • 21
  • You forgot to post the PHP code? – Amal Murali Sep 19 '13 at 21:57
  • he didnt do any PHP because there are no forms, either full JavaScript or just not ownig xampp server yet. – Kyslik Sep 19 '13 at 22:01
  • sorry forgot to add the php code – user2725936 Sep 19 '13 at 22:04
  • Not really a good idea to do a calculator with a php form, you must use JavaScript eventually to add the calculated values to the dom, unless you echo it out to your site with a ugly reload :) – Jonast92 Sep 19 '13 at 22:06
  • oh ok..cos i want to use it with wordpress and eventually use the calculator to be saved within each user profile so that the user can come back to view is calculated value – user2725936 Sep 19 '13 at 22:09
  • @Jonast92 how do u suggest i do that so that i can have a calculator for each user on my wordpress site to login and save his calculated result? – user2725936 Sep 19 '13 at 22:14
  • @user2725936, you can *easily `*`* convert this into an [Ajaxified Shortcode](http://stackoverflow.com/a/13614297/1287812). . . . . . . . . `*` First, you gotta find a JS/jQuery calculator, then a `Save results` button (or live changes) would dispatch the Ajax/PHP to save it into the user's meta data. – brasofilo Sep 19 '13 at 23:31

1 Answers1

0

Use var_dump($_POST) to see under what keys your values are stored and if they are stored. (Maybe you're not posting). Once you know where they are stored just add them together.

As long as you don't have a debugger.. var_dump is your friend.

BogdanM
  • 625
  • 1
  • 6
  • 10