Howzit all
I need help again with bit of code. What it should do is calculate a total automatically as soon as the unit_price value and markup percentage value is added.into a textbox, and then it must write those values to database with all the other from an invoice page. How on earth do I do it, because so far I cant get it to calculate let alone write to db. pLease please help me?
Oh yes, and what would be a class in javascript to use rather than math.round because it rounds my values to 1, I want a decimal of 2. Please help.
And how can I in this below piece of code add every price coming through to eache other so that I have a correct total to display and not every value added on to each other Eg the way it is now 11131617 if i had 4 respective values 11, 13, 16, 17.
Here the javascript code:
<script>
<!--
function calc(price, markup)
{
var our_price = document.getElementById("markup");
var total_total = document.getElementById("total_total");
our_price.value = Math.round((price+(price*(markup/100)))*100)/100; total_total.value = total_total.value+our_price.value;
}
//--><!--
function checkForm()
{
var f = document.stockForm;
else if (f.stock_description.value == '')
{
alert('Please enter a valid stock Description!');
return false;
}
else if (f.stock_type_ID.value == '')
{
alert('Please enter a valid stock Type!');
return false;
}
else if (f.stock_unitprice.value == '' || isNaN(parseInt(f.stock_unitprice.value)) || parseInt(f.stock_unitprice.value) < 0)
{
alert('Please enter a valid stock unit price!');
return false;
}
}
function kH(e) {
var pK = document.all? window.event.keyCode:e.which;
return pK != 13;
}
document.onkeypress = kH;
if (document.layers) document.captureEvents(Event.KEYPRESS);
//-->
</script>
And heres the php code;
<?php
print ("<td align=\"center\">R<input type=\"text\" value=\"stock_unitprice\">". $stock['stock_unitprice'] ."</td>
<td><input type=\"text\" size=2 value=\"stock_markup\" onkeyup=\"calc(" . $stock['stock_unitprice'] . ",this.value)\">%</td>
<td>R <input type=\"text\" size=7 value=\"stock_ourprice\" id=\"markup\"></td>
");
?>
<tr>
<td height="43" align="right" class="header">TOTAL(Incl):</td>
<td><strong>R</strong><input type="text" id="total_total" value="" size="10"></td>
</tr>