HI, I'm worrying with a calendar, trying to send to & print out
a list of entries. I must not be doing the "OnCalc " function right
(in the Html or Php)?
Doing an alert of the values in this following presents the right
values but no results. Any help?
--------------------
-------------------------------------------
a list of entries. I must not be doing the "OnCalc " function right
(in the Html or Php)?
Doing an alert of the values in this following presents the right
values but no results. Any help?
--------------------
HTML:
<input name="btnEquals" type="Button" value=" = " onclick="Operation('=')"></TD>
</TR></TABLE>
<INPUT type="image" src="programmer.gif" alt="submit button"><p>
</FORM>
<font face="Verdana, Arial, Helvetica" size=2>
<SCRIPT LANGUAGE="JavaScript">
var FKeyPad = document.Keypad;
var purpose = 0;
var Accumulate = 0;
var FlagNewNum = false;
var PendingOp = "";
function NumPressed (Num)
{
if (FlagNewNum)
{ FKeyPad.ReadOut.value = Num;
FlagNewNum = false;
}
else
{
if (FKeyPad.ReadOut.value == "0")
FKeyPad.ReadOut.value = Num;
else
FKeyPad.ReadOut.value += Num;
}
}
function Operation (Op)
{
var Readout = FKeyPad.ReadOut.value;
if (FlagNewNum && PendingOp != "=");
else
{
FlagNewNum = true;
if ( '+' == PendingOp )
{
var temp = Accumulate;
Accumulate += parseFloat(Readout);
OnCalc(temp,PendingOp,Readout,Accumulate);
}
else if ( '-' == PendingOp )
{
var temp = Accumulate;
Accumulate -= parseFloat(Readout);
OnCalc(temp,PendingOp,Readout,Accumulate);
}
else if ( '/' == PendingOp )
{
var temp = Accumulate;
Accumulate /= parseFloat(Readout);
OnCalc(temp,PendingOp,Readout,Accumulate);
}
else if ( '*' == PendingOp )
{
var temp = Accumulate;
Accumulate *= parseFloat(Readout);
OnCalc(temp,PendingOp,Readout,Accumulate);
}
else
{
Accumulate = parseFloat(Readout);
}
FKeyPad.ReadOut.value = Accumulate;
PendingOp = Op;
}
}
function Decimal ()
{
var curReadOut = FKeyPad.ReadOut.value;
if (FlagNewNum)
{
curReadOut = "0.";
FlagNewNum = false;
}
else
{
if
(curReadOut.indexOf(".") == -1)
curReadOut += ".";
}
FKeyPad.ReadOut.value = curReadOut;
}
function ClearEntry ()
{
FKeyPad.ReadOut.value = "0";
FlagNewNum = true;
}
function Clear ()
{
Accumulate = 0;
PendingOp = "";
ClearEntry();
}
function Neg ()
{
FKeyPad.ReadOut.value = parseFloat(FKeyPad.ReadOut.value) * -1;
}
function Percent ()
{
FKeyPad.ReadOut.value = (parseFloat(FKeyPad.ReadOut.value) / 100) *
parseFloat(Accumulate);
}
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)}
<!-- use ajax - OnCalc function to send data to your database. -->
function OnCalc(value1,op,value2,total)
alert(value1);
{
var expression = value1 + op +value2 +'='+ total;
alert(expression);
}
</SCRIPT>
</body></html>
PHP:
<?php
header( "refresh:5;url='http://localhost/home/calcprint.php'");
echo 'You\'ll be redirected in about 5 secs. If not, click <a href="http://localhost/home/calcprint.php">here</a>.';
include ('gethomedb.php');
// now connected to database
if(!empty($_POST["submit"]))
{
echo '<script type="text/javascript">'
, 'OnCalc();'
, '</script>';
$id = $_POST['id'];
$purpose=$_POST['purpose'];
$value1=$_POST['value1'];
$op=$_POST['op'];
$value2=$_POST['value2'];
$total=$_POST['total'];
$name = $_POST['id'];
if(isset($_POST['id']))
{
$fetch="SELECT * FROM calculator";
$result = mysqli_query($con,$fetch);
if(!$result)
{echo "Error:".(mysqli_error($con));}
// ===========================================================
$query = "
INSERT INTO calculator (purpose, value1, op, value2, total)
VALUES ('$purpose','$value1','$op','$value2','$total')";
mysqli_query($con, $query);
mysqli_close($con);
}
}
?>