Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: trying to pass JS to PHP  (Read 4874 times)

0 Members and 1 Guest are viewing this topic.

12Strings

    Topic Starter


    Rookie

    • Experience: Experienced
    • OS: Windows 7
    trying to pass JS to PHP
    « on: December 24, 2014, 02:06:23 PM »
    I need for someone to advise how I'm going wrong with passing my
    JS "function(OnCalc()" in the FORM named "calculator.html" to my database:
    My form presents as desired but submitting enters 0.00 values.
    I just need to know if the following syntax and procedures are correct.
    Thanks.
    --------------------------------------------------------
     this is from "calculator,html"

    Code: [Select]
    <FORM name="Keypad" action="http://localhost/home/calc_redirect.php" method="post"> // ??????

    if (value1 == parseInt(num))
       {value1.value = parseInt(value1.value)}
    else
       {value1.value = parsefloat(value1.value)}

    if (value2 == parseInt(num))
       {value2.value = parseInt(value2.value)}
    else
       {value2.value = parsefloat(value2.value)}

    if (total == parseInt(num))
       {total.value = parseInt(total.value)}
    else
       {total.value = parsefloat(total.value)}
     
    /* var expression = value1 + op +value2 +'='+ total;
    alert(expression); */
     }
    function OnCalc(value1,op,value2,total)
    {
    </SCRIPT>
    -------------------------------------------------------
    Code: [Select]
    <?php
    // name of this is "calc_redirect" 
    /* The header() sends a raw HTTP/1.1 specification specific header. header() must be called before any actual output is sent */
    /* Redirect browser */
    header("Location: http://localhost/home/calculator.php"); // ?????
    exit;
    ?>
    --------------------------------------------------------
    this is from "calculator.php":
    Code: [Select]
    $query = "
    INSERT INTO calculator (purpose, value1, op, value2, total)
    VALUES ('$purpose','$value1','$op','$value2','$total')";
    mysqli_query($con, $query);
    mysqli_close($con);
       ?>
    Code: [Select]
    <a href="http://localhost/home/calc_print.php">Print</a>
    </center></body></html>
    --------------------------------------------------------