edrew04 Posted January 6, 2009 Share Posted January 6, 2009 the reset button wont work any more after the answer was outputted .i used the \b escape character but still wont work, i think i need a help from you guys. please help me here: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Machine Problem #1: Calculator</title> <script language="javscript" type="text/javascript"> <!-- function addbool(){ calc.txtInput.value = '-'+calc.txtInput.value; } function resetform(){ calc.bool.disabled = 0; calc.decimal.disabled = 0; calc.add.disabled = 0; calc.subtract.disabled = 0; calc.multiply.disabled = 0; calc.divide.disabled = 0; } function passval(){ calc.txtStored.value = calc.txtInput.value; calc.txtInput.value = ""; } function disablebtn(){ calc.divide.disabled = 1; calc.multiply.disabled = 1; calc.subtract.disabled = 1; calc.add.disabled = 1; calc.decimal.disabled = 0; } //--> </script> <style type="text/css"> input.field{ width:100%; height:30px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:18px; text-align:right; } .btn{ width:40px; height:40px; } .btn0{ width:100%; height:40px; } </style> </head> <body> <?php /* =============================================================================================================== TREND-1S,2008-2009,2nd SEM MACHINE PROBLEM #1 JAN 10, 2009 CARDANO,EDREW S.(20060121451) =============================================================================================================== */ /*Hi maam its me!, Edrew Cardano, Trend 1s- 2nd sem, I'll explain my work, Happy New Year! c^^,) */ if($_GET['txtTypeof']=='add') /*the variable txtTypeof is a hidden input type, it is where the operations will fall*/ { $addens1=$_GET['txtStored'];/*the variable txtStored is a hidden input type, it is where the 1st input is read*/ $addens2=$_GET['txtInput'];/*the variable txtStored is not a hidden input type, it is where the 2nd input is read*/ $val=$addens1+$addens2;/* it will be echoed here for it will be echoed in the txtInput*/ } elseif($_GET['txtTypeof']=='subtract') { $minuend=$_GET['txtStored']; $subtrahend=$_GET['txtInput']; $val=$minuend-$subtrahend; } elseif($_GET['txtTypeof']=='divide') { $dividend=$_GET['txtStored']; $divisor=$_GET['txtInput']; $val=$dividend/$divisor; } elseif($_GET['txtTypeof']=='multiply') { $multiplicand=$_GET['txtStored']; $multiplier=$_GET['txtInput']; $val=$multiplicand*$multiplier; } elseif($_GET['txtTypeof']=='multiply')/*this is the reset button,i need to make a code to reset values entirely.*/ { $_GET['txtInput'] = "";/*I'm trying hard to make the code to delete the last session but still... :-( */ } else /*it seemed to be redundant but useful as well. c^^,)*/ $val = ''; ?> <form id="" name="calc" method="get" action="index.no.code3.php"> <table width="100%" border="0"> <tr> <td align="center" valign="middle"><table width="180" border="0"> <tr> <td colspan="4" align="center" valign="middle"><input name="txtInput" type="text" class="field" id="txtInput" style="width:100%;" maxlength="12" value=" <?php if ($_GET['txtTypeof']=='reset') { echo $val->reset('Clear'); function reset($val) { $val = ""; } } else echo $val; /*here is where i called the variable $val for the txtbox's result*/ ?>" /> <input type="hidden" name="txtStored" id="txtStored"/> <input type="hidden" name="txtTypeof" id="txtTypeof"/> </td> </tr> <tr> <td align="center" valign="middle"><label> <input name="7" type="button" class="btn" id="7" value="7" OnClick="calc.txtInput.value += '7'"/> </label></td> <td align="center" valign="middle"><input name="8" type="button" class="btn" id="8" value="8" OnClick="calc.txtInput.value += '8'"/></td> <td align="center" valign="middle"><input name="9" type="button" class="btn" id="9" value="9" OnClick="calc.txtInput.value += '9'"/></td> <td align="center" valign="middle"><input name="divide" type="button" class="btn" id="divide" value="/" OnClick="disablebtn(); passval(); calc.txtTypeof.value = 'divide';"/></td> </tr> <tr> <td align="center" valign="middle"><input name="4" type="button" class="btn" id="4" value="4" OnClick="calc.txtInput.value += '4'"/></td> <td align="center" valign="middle"><input name="5" type="button" class="btn" id="5" value="5" OnClick="calc.txtInput.value += '5'"/></td> <td align="center" valign="middle"><input name="6" type="button" class="btn" id="6" value="6" OnClick="calc.txtInput.value += '6'"/></td> <td align="center" valign="middle"><input name="multiply" type="button" class="btn" id="multiply" value="*" OnClick="disablebtn(); passval(); calc.txtTypeof.value = 'multiply';"//></td> </tr> <tr> <td align="center" valign="middle"><input name="3" type="button" class="btn" id="3" value="1" OnClick="calc.txtInput.value += '1'"/></td> <td align="center" valign="middle"><input name="2" type="button" class="btn" id="2" value="2" OnClick="calc.txtInput.value += '2'"/></td> <td align="center" valign="middle"><input name="1" type="button" class="btn" id="1" value="3" OnClick="calc.txtInput.value += '3'"/></td> <td align="center" valign="middle"><input name="subtract" type="button" class="btn" id="subtract" value="-" OnClick="disablebtn(); passval(); calc.txtTypeof.value = 'subtract';"//></td> </tr> <tr> <td align="center" valign="middle"><input name="0" type="button" class="btn" id="0" value="0" OnClick="calc.txtInput.value += '0'"/></td> <td align="center" valign="middle"><input name="bool" type="button" class="btn" id="bool" value="+/-" OnClick="addbool();this.disabled=1;"/></td> <td align="center" valign="middle"><input name="decimal" type="button" class="btn" id="decimal" value="." OnClick="this.disabled=1; calc.txtInput.value += '.'"/></td> <td align="center" valign="middle"><input name="add" type="button" class="btn" id="add" value="+" OnClick="disablebtn(); passval(); calc.txtTypeof.value = 'add';"//></td> </tr> <tr> <td colspan="2" align="center" valign="middle"><input name="reset" type="reset" class="btn0" id="reset" value="CE"/></td> <td colspan="2" align="center" valign="middle"><input name="equal" type="submit" class="btn0" id="equal" value="=" /></td> </tr> </table> <br /></td> </tr> </table> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/139649-php-calculator-help-for-finnishing-touches/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.