...

View Full Version : use php instead of javascript



varma51
07-20-2012, 03:43 PM
hi frends dis is my code for caluculator..i use java script in dis..instead of using javascript can use php..



<html>
<form action=" " method="post" name="Keypad">

<table width='200' cellpadding='2' cellspacing='5' border='1'>
<tr>
<td colspan=3 align=middle>
<input name="ReadOut" type="Text" size=15 value="0" width=100%>
</td> </tr>
<tr><td align="center">
<input type="button" value=" 7 " name="seven" onclick="NumPressed(7)">
</td>
<td>
<input type="button" value=" 8 " name="eight" onclick="NumPressed(8)">
</td>
<td>
<input type="button" value=" 9 " name="nine" onclick="NumPressed(9)">
</td>
<td>
<input type="button" value=" / " name="divide" onclick="Operation('/')">
</td>
</tr>
<tr><td align="center">
<input type="button" value=" 4 " name="four" onclick="NumPressed(4)">
</td>
<td>
<input type="button" value=" 5 " name="five" onclick="NumPressed(5)">
</td>
<td>
<input type="button" value=" 6 " name="six" onclick="NumPressed(6)">
</td>
<td>
<input type="button" value=" * " name="multiply" onclick="Operation('*')">
</td>
</tr>

<tr><td align="center">
<input type="button" value=" 1 " name="one" onclick="NumPressed(1)">
</td>
<td>
<input type="button" value=" 2 " name="two" onclick="NumPressed(2)">
</td>
<td>
<input type="button" value=" 3 " name="three" onclick="NumPressed(3)">
</td>
<td>
<input type="button" value=" - " name="Substraction" onclick="Operation('-')">
</td>
</tr>



<tr><td align="center">
<input name="btnClearEntry" type="Button" value=" C " onclick="ClearEntry()">
</td>

<td>
<input name="btnZero" type="Button" value=" 0 " onclick="NumPressed(0)">
</td>
<td>
<input type="button" value=" = " name="equal" onclick="Operation('=')">
</td>
<td>
<input type="button" value=" + " name="add" onclick="Operation('+')">
</td>
</tr>
</table>
</form>
<?php

var FKeyPad = document.Keypad;
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 )
Accumulate += parseFloat(Readout);
else if ( '-' == PendingOp )
Accumulate -= parseFloat(Readout);
else if ( '/' == PendingOp )
Accumulate /= parseFloat(Readout);
else if ( '*' == PendingOp )
Accumulate *= parseFloat(Readout);
else
Accumulate = parseFloat(Readout);
FKeyPad.ReadOut.value = Accumulate;
PendingOp = Op;
}
}
function ClearEntry () {
FKeyPad.ReadOut.value = "0";
FlagNewNum = true;
}


</script>
</html>

Keleth
07-20-2012, 03:54 PM
Yes you can use PHP?

Have you tried doing it yourself at all?

varma51
07-21-2012, 07:04 AM
ya boss i'm trying but i'm nt getting it..bcoz i'm new 4r php can u help me plz..i wnt it in pure php

felgall
07-21-2012, 07:50 AM
So each time a key is pressed you need to submit the form and reload the page so that the PHP can read which button was pressed and perform the appropriate action.

jdswebservice
07-21-2012, 09:38 PM
Ok, enough with the l33t speak broski. :/ seriously, this is a coding forum. If you want to be taken at least SOMEWHAT seriously, at least use correct english.

Now, as i seemed to have posted in another topic, this board isn't for someone just to write code for you. At least ATTEMPT writing the code yourself. If you have any errors come back and we'll be more then happy to help you.

If you want the code to be written for you then look in the projects board/category.

Thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum