#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    3
    Rep Power
    0

    Calculate Form field on the fly


    Wondering if you can help?

    I am working on a script that allows to introducing 3 fields quantity, price, discount (%), and I would like to display and store an automatic calculated field (Total) executing this operation:

    quantity * price - discount(%) = Total

    May you help me to code all operations in order to display (not to store) Total?

    Thank you very much in advance,
    Pere

    This my code:

    ---dbase connect
    PHP Code:
    if($_POST["do"]=="store")
    {
    $prod_nombreproducto=$_POST["prod_nombreproducto"];
    $prod_cantidad=$_POST["prod_cantidad"];
    $prod_preciounitario=$_POST["prod_preciounitario"];
    $prod_descuento=$_POST["prod_descuento"];
    $prod_totalproducto=$_POST["prod_totalproducto"]; 

    PHP Code:
    $query="insert into pm_productos value('$prod_nombreproducto','$prod_cantidad',
    '
    $prod_preciounitario','$prod_descuento','$prod_totalproducto')"

    Quantity: <input type="text" name="prod_cantidad" size="20">
    Price: <input type="text" name="prod_preciounitario" size="20">
    Discount (%):<input type="text" name="prod_descuento" size="20">
    Total:<input type="text" name="prod_totalproducto" size="20"></td>
    </tr>[/PHP]
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,985
    Rep Power
    375
    you are already DISPLAYING it
    Total:<input type="text" name="prod_totalproducto" size="20"></td>

    am not sure i follow?

    if you want run time changes then use JQUERY/AJAX.

IMN logo majestic logo threadwatch logo seochat tools logo