/    Sign up×
Community /Pin to ProfileBookmark

calculator doesn’t substract value and total can’t be retrieve

what my outcome is to retrieve value from database when user pick an id from dropdown box into the amount textbox. then, user will insert the cash value. finally press button equal to subtracts the amount and cash inserting it in balance textbox.

here are my coding:

[code=php]
<script type=”text/javascript”>

function substract(){

pay = Number(document.calc.cash.value)
amount = Number(document.calc.amount.value)
balance = Number(document.calc.balance.value)
balance.value = (pay – amount).toFixed(2);
}
</script>

<script type=”text/javascript”>
function showpayment(str)
{
if (str==””)
{
document.getElementById(“payment”).innerHTML=””;
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById(“payment”).innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open(“GET”,”payment.php?q=”+str,true);
xmlhttp.send();
}
</script>

</head>

<body>

<form action=”” method=”post” name=”calc” style=”margin: auto; height: 331px; width: 514px; background-color: #008000; color: #00FF00; font-family: ‘Arial Rounded MT Bold’; margin-bottom: auto; margin-left: auto; margin-right: auto; margin-top: auto;”>
<input name=”amount” type=”hidden” />
<div class=”style1″ style=”height: 335px; margin-left: auto; margin-right: auto; width: 517px;”>
&nbsp;<br />
<table style=”width: 87%”>
<tr>
<td colspan=”2″ style=”height: 34px” class=”style8″>&nbsp;&nbsp; TABLE ID</td>
<td class=”style6″ style=”width: 29px; height: 34px;”>:</td>
<td style=”width: 41px; height: 34px;”></td>
<td colspan=”2″ style=”height: 34px”>
<select name=”tableid” onchange=”showpayment(this.value)” style=”width: 171px”>
<option selected=”selected” value=”0″>PLEASE SELECT AN ID
</option>
<option value=”T1″>T1</option>
<option value=”T2″>T2</option>
<option value=”T3″>T3</option>
<option value=”T4″>T4</option>
<option value=”T5″>T5</option>
<option value=”T6″>T6</option>
<option value=”T7″>T7</option>
<option value=”T8″>T8</option>
<option value=”T9″>T9</option>
<option value=”T10″>T10</option>
<option>T11</option>
<option value=”T12″>T12</option>
<option value=”T13″>T13</option>
<option value=”T14″>T14</option>
<option value=”T15″>T15</option>
<option value=”T16″>T16</option>
<option value=”T17″>T17</option>
<option value=”T18″>T18</option>
<option value=”T18″>T18</option>
<option value=”T19″>T19</option>
<option value=”T20″>T20</option>
<option value=”T21″>T21</option>
<option value=”T22″>T22</option>
<option value=”T23″>T23</option>
<option value=”T24″>T24</option>
<option value=”T25″>T25</option>
</select></td>
<td style=”height: 34px”></td>
<td style=”width: 18px; height: 34px;”></td>
<td style=”width: 19px; height: 34px;”></td>
<td style=”width: 10px; height: 34px;”></td>
<td style=”height: 34px; width: 72px;”></td>
</tr>
<tr>
<td style=”width: 72px” class=”style8″>&nbsp;</td>
<td style=”width: 18px” class=”style8″>&nbsp;</td>
<td style=”width: 29px”>&nbsp;</td>
<td style=”width: 41px”>&nbsp;</td>
<td style=”width: 12px”>&nbsp;</td>
<td style=”width: 41px”>&nbsp;</td>
<td>&nbsp;</td>
<td style=”width: 18px”>&nbsp;</td>
<td style=”width: 19px”>&nbsp;</td>
<td style=”width: 10px”>&nbsp;</td>
<td style=”width: 72px”>&nbsp;</td>
</tr>
<tr>
<td colspan=”2″ class=”style8″>&nbsp;&nbsp; AMOUNT</td>
<td class=”style6″ style=”width: 29px”>:</td>
<td class=”style6″ style=”width: 41px”>RM</td>
<td colspan=”2″ class=”style8″>
<input name=”total” style=”width: 80px” type=”text” id=”payment”/></td>
<td>&nbsp;</td>
<td style=”width: 18px”>
<input name=”one” type=”button” value=”1″ onclick=”calc.cash.value+=’1′” class=”style7″ style=”width: 30px; height: 30px;”/></td>
<td style=”width: 19px”>
<input name=”two” type=”button” value=”2″ onclick=”calc.cash.value+=’2′” class=”style7″ style=”width: 30px; height: 30px”/></td>
<td style=”width: 10px”>
<input name=”three” type=”button” value=”3″ onclick=”calc.cash.value+=’3′” class=”style7″ style=”width: 30px; height: 30px”/></td>
<td style=”width: 72px”>&nbsp;</td>
</tr>
<tr>
<td style=”width: 72px” class=”style8″>&nbsp;</td>
<td style=”width: 18px” class=”style8″>&nbsp;</td>
<td style=”width: 29px”>&nbsp;</td>
<td style=”width: 41px”>&nbsp;</td>
<td style=”width: 12px” class=”style8″>&nbsp;</td>
<td style=”width: 41px” class=”style8″>&nbsp;</td>
<td>&nbsp;</td>
<td style=”width: 18px”>
<input name=”four” type=”button” value=”4″ onclick=”calc.cash.value+=’4′” class=”style7″ style=”width: 30px; height: 30px”/></td>
<td style=”width: 19px”>
<input name=”five” type=”button” value=”5″ onclick=”calc.cash.value+=’5′” class=”style7″ style=”width: 30px; height: 30px”/></td>
<td style=”width: 10px”>
<input name=”six” type=”button” value=”6″ onclick=”calc.cash.value+=’6′” class=”style7″ style=”width: 30px; height: 30px”/></td>
<td style=”width: 72px”>&nbsp;</td>
</tr>
<tr>
<td colspan=”2″ class=”style8″>&nbsp;&nbsp; CASH</td>
<td class=”style6″ style=”width: 29px”>:</td>
<td class=”style6″ style=”width: 41px”>RM</td>
<td colspan=”2″ class=”style8″>
<input name=”cash” style=”width: 80px” type=”text” /></td>
<td>&nbsp;</td>
<td style=”width: 18px”>
<input name=”seven” type=”button” value=”7″ onclick=”calc.cash.value+=’7′” class=”style7″ style=”width: 30px; height: 30px;”/></td>
<td style=”width: 19px”>
<input name=”eight” type=”button” value=”8″ onclick=”calc.cash.value+=’8′” class=”style7″ style=”width: 30px; height: 30px”/></td>
<td style=”width: 10px”>
<input name=”nine” type=”button” value=”9″ onclick=”calc.cash.value+=’9′” class=”style7″ style=”width: 30px; height: 30px”/></td>
<td style=”width: 72px”>&nbsp;</td>
</tr>
<tr>
<td style=”width: 72px” class=”style8″>&nbsp;</td>
<td style=”width: 18px” class=”style8″>&nbsp;</td>
<td style=”width: 29px”>&nbsp;</td>
<td style=”width: 41px”>&nbsp;</td>
<td style=”width: 12px” class=”style8″>&nbsp;</td>
<td style=”width: 41px” class=”style8″>&nbsp;</td>
<td>&nbsp;</td>
<td style=”width: 18px”>
<input name=”zero” type=”button” value=”0″ onclick=”calc.cash.value+=’0′” class=”style7″ style=”width: 30px; height: 30px”/></td>
<td style=”width: 19px”>
<input name=”dot” style=”height: 30px; width: 30px” type=”button” value=”.” onclick=”calc.cash.value+=’.'” class=”style7″/></td>
<td style=”width: 10px”>
<input name=”equal” type=”button” value=”=” onclick=”substract()” class=”style7″ style=”width: 30px; height: 30px”/></td>
<td style=”width: 72px”>&nbsp;</td>
</tr>
<tr>
<td colspan=”2″ class=”style8″>&nbsp;&nbsp;BALANCE&nbsp;</td>
<td class=”style6″ style=”width: 29px”>:</td>
<td class=”style6″ style=”width: 41px”>RM</td>
<td colspan=”2″ class=”style8″>
<input name=”txtbal” style=”width: 80px” type=”text” /></td>
<td>&nbsp;</td>
<td style=”width: 18px”>&nbsp;</td>
<td style=”width: 19px”>&nbsp;</td>
<td style=”width: 10px”>&nbsp;</td>
<td style=”width: 72px”>&nbsp;</td>
</tr>
<tr>
<td style=”width: 72px”>&nbsp;</td>
<td style=”width: 18px”>&nbsp;</td>
<td style=”width: 29px”>&nbsp;</td>
<td style=”width: 41px”>&nbsp;</td>
<td style=”width: 12px”>&nbsp;</td>
<td style=”width: 41px”>&nbsp;</td>
<td>&nbsp;</td>
<td style=”width: 18px”>&nbsp;</td>
<td style=”width: 19px”>&nbsp;</td>
<td style=”width: 10px”>&nbsp;</td>
<td style=”width: 72px”>&nbsp;</td>
</tr>
</table>
<br />
&nbsp;&nbsp;&nbsp;
<input class=”style4″ name=”update” style=”width: 110px; height: 30px;” type=”button” value=”DONE” />&nbsp;&nbsp;&nbsp;
<input class=”style5″ name=”print” type=”submit” value=”PRINT RECEIPT” style=”height: 30px” /></div>
</form>

[/code]

here is the payment.php:

[code=php]
<?php

$q=$_GET[“q”];
include(“connection.php”);

$sql=”SELECT * FROM orderrecord WHERE Category = ‘”.$q.”‘ Payment = ‘Unpaid’ “;
$result = mysql_query($sql);
session_start();

while($row = mysql_fetch_array($result))
{
document.getElementById(‘payment’).value = $row[‘Total’];
}

mysql_close($conn);
?>
[/code]

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @stepbystep spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...