Hi, I could use some help passing a function or its variables to
a php file. Since JS is so verbose I'm posting succinct code
to demonstrate my path. Everything works except the values sent
to php are zeros. Thanks in advance.
(sending the form to:)
<FORM name="Keypad" method="post" action="http://localhost/home/calcinsert.php">
<input name="btnEquals" type="Button" value=" = " onclick="Operation('=')"></TD>
</TR></TABLE>
<br>
(form submission)
var FKeyPad = document.Keypad;
(this section is where I got lost)
if (value1 == parseInt(num)) // integer or decimal ?
<input id="rNo" type="radio" name="YesNo" value="No" onclick="this.form.submit();">
<label for="rNo">calculate</label><br>
<input id="rYes" type="radio" name="YesNo" value="Yes" onClick="location.href='http://localhost/home/calcprint.php';"
<label for="rYes">print</label><br>
</FORM>
<font face="Verdana, Arial, Helvetica" size=2>
<SCRIPT LANGUAGE="JavaScript">
{value1.value = parseInt(value1.value)}
else
{value1.value = parsefloat(value1.value)}
op.value = parsefloat(op.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)}
function OnCalc(value1,op,value2,total)
{
/* var expression = purpose + value1 + op +value2 +'='+ total;
alert(expression); */
}
</SCRIPT>
</body></html>
(this is the file I'm trying to send the variables to)
<?php
$servername = "localhost";$username = "root";$password = "cookie";$dbname = "homedb";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn)
{ die("Connection failed: " . mysqli_connect_error()); }
$sql = "INSERT INTO calculator (purpose, value1, op, value2, total)
VALUES ('purpose', 'value1', 'op', 'value2', 'total')";
if (mysqli_query($conn, $sql))
{ echo "New record created successfully"; }
else
{ echo "Error: " . $sql . "<br>" . mysqli_error($conn); }
mysqli_close($conn);
header( 'Location: http://localhost/home/calculator.html' );
exit();
?>