Good day all:
I have an editable invoice that I have added a sales tax option with a js function doMath(). Prior to my modification with the sales tax option all worked well. the invoice which code is the following:
<textarea id="address" rows="6" cols="38" disabled="true">Website:
Email:
TaxID:
</textarea >
<div id="vehicleid"><label><strong><u>Vehicle Information</u></strong></label><p>Year: <?php echo $edit_caryear?></p><p>Type: <?php echo $dhtmlgoodies_categoryupdate?></p><p>Make: <?php echo $dhtmlgoodies_subcategoryupdate?></p><p>ClientID# <?php echo $edit_clientID?></p><p>Current Mileage <?php echo $edit_mileage?></p></div>
<!--</div>-->
<!--<div id="logo">
<div id="logoctr">
<a href="javascript:;" id="change-logo" title="Change logo">Change Logo</a>
<a href="javascript:;" id="save-logo" title="Save changes">Save</a>
|
<a href="javascript:;" id="delete-logo" title="Delete logo">Delete Logo</a>
<a href="javascript:;" id="cancel-logo" title="Cancel changes">Cancel</a>
</div>
<div id="logohelp">
<input id="imageloc" type="text" size="50" value="" /><br />
(max width: 540px, max height: 100px)
</div>
<img id="image" src="images/logo.png" alt="logo" width="280" height="33" />
</div>-->
</div>
<div style="clear:both"></div>
<br>
<div id="customer">
<?php echo $edit_firstname ?> <?php echo $edit_lastname?><p><?php echo $edit_address?></p><p><?php echo $edit_city?>, <?php echo $edit_state?>, <?php echo $edit_zipcode?></p>
</div>
<div id=invoicehead>
<table id="meta">
<tr>
<td class="meta-head">Invoice #</td>
<td><textarea style="background: transparent;" name="invoicenum" id="invoicenun" disabled="true"><?php
srand(time());
$random = (rand()%1000000);
print("$random");
?></textarea></td>
</tr>
<tr>
<td class="meta-head">Date</td>
<td><textarea name="date" id="date">December 15, 2009</textarea></td>
</tr>
<tr>
<td class="meta-head">Amount Due</td>
<td><div name="due" class="due">$0.00</div></td>
</tr>
</table>
</div>
<table id="items">
<tr>
<th>Item</th>
<th>Description</th>
<th>Unit Cost</th>
<th>Quantity</th>
<th>Price</th>
</tr>
<tr class="item-row">
<td class="item-name"><div class="delete-wpr">
<!--<label for=\"dhtmlgoodies_category\">Make:</label>-->
<?php echo $edit_servicearea?><br>
<!--<SELECT NAME="edit_servicearea">
<OPTION>Select One
<OPTION>Air Intake
<OPTION>Brake
<OPTION>Clutch
<OPTION>Cooling System
<OPTION>Driveshaft & Axle
<OPTION>Engine Mechanical
<OPTION>Exhaust
<OPTION>Steering
<OPTION>Suspension
<OPTION>Transmission
<OPTION>Other
</SELECT>-->
<a class="delete" href="javascript:;" title="Remove row">X</a></div></td>
<td class="description">
<textarea name="servicedesc" cols="255" rows="20"><?php echo str_replace('<br/>', "\n", "$inputbox");?></textarea></td>
<td><textarea name="cost" class="cost">$0.00</textarea></td>
<td><textarea name="qty" class="qty">1</textarea></td>
<td><span name="price" class="price">$0.00</span></td>
</tr>
<tr class="item-row">
<td class="item-name"><div class="delete-wpr">
<textarea name="Labor rate" cols="20" rows="3">Labor</textarea><a class="delete" href="javascript:;" title="Remove row">X</a></div></td>
<td class="description" wrap=virtual><textarea>Labor rate for the performance of work --excluding cost for parts.</textarea></td>
<td><textarea class="cost">$75.00</textarea></td>
<td><textarea class="qty" rows="2" cols="10">0</textarea></td>
<td><span class="price">$0.00</span></td>
</tr>
<tr id="hiderow">
<td colspan="5"><a id="addrow" href="javascript:;" title="Add a row">Add a row</a></td>
</tr>
<tr>
<td colspan="2" class="blank"> </td>
<td colspan="2" class="total-line">Subtotal</td>
<td class="total-value"><div id="subtotal">$0.00</div></td>
</tr>
<tr>
<td colspan="2" class="blank"> </td>
<td colspan="2" class="tax-line" style="text-align: left" valign="top">INCLUDE TAX? <input type = "checkbox" id = "taxbox" onclick = "doMath()"><br>DC
5.576%</td>
<td class="total-value"><textarea class="tax" id="tax" >$0.00</textarea></td> </tr>
<tr>
<td colspan="2" class="blank"> </td>
<td colspan="2" class="total-line">Total</td>
<td class="total-value"><div id="total">$0.00</div></td>
</tr>
<tr>
<td colspan="2" class="blank"> </td>
<td colspan="2" class="total-line">Amount Paid</td>
<td class="total-value"><textarea id="paid">$0.00</textarea></td>
</tr>
<tr>
<td colspan="2" class="blank"> </td>
<td colspan="2" class="total-line balance">Balance Due</td>
<td class="total-value balance"><div class="due">$0.00</div></td>
</tr>
</table>
</div>
</div>
<div>
<SCRIPT LANGUAGE="JavaScript">
document.write('<form><input type=button value="Refresh" onClick="history.go()"></form>')
</script>
</div><br>
<div id="option">
<input type="button" id="button" value="Return to Main Menu" onclick="window.location='/andy/addentry.php' " />
<input type="hidden" name="servicedesc" value="<?php echo $_POST['servicedesc']; ?>">
<br>
<p>
<! I added this button, so that it returns us to the main Menu.>
<INPUT TYPE="button" onClick="window.print()" value="Print" /><br>
</p>
<p><! The above button Clears all the Field's contents ><input type="submit" name="submit" value="Save Changes">
</div>
</form>
the section of the code higlighted in red is where my problem arises. To achieve the desired results(at least so that I thought), I included the following function in my js function file which is as follows:
function update_total() {
var total = 0;
$('.price').each(function(i){
price = $(this).html().replace("$","");
if (!isNaN(price)) total += Number(price);
});
total =roundNumber(total,2);
$('#subtotal').html("$"+total);
$('#total').html("$"+total);
//$('#tax').html("$"+total);
update_balance();
}
var taxRate = .0575;
function doMath(){
//var subtotal = 0.00;//$('.price').each(function(i);
var subtotal = $('#subtotal').value;//.html("$"+total);
if (document.getElementById("taxbox").checked) {
tax = subtotal* taxRate; //DC 5.576%
tax = roundNumber(tax,2);//the 2 represent the number of digits to round numbers to after decimal point
//tx = " Incl. 5.576%";
}
document.getElementById("tax").value = "$" +tax;
}function update_balance() {
var due = $("#total").html().replace("$","") - $("#paid").val().replace("$","");
due = roundNumber(due,2);
$('.due').html("$"+due);
}
function update_price() {
var row = $(this).parents('.item-row');
var price = row.find('.cost').val().replace("$","") * row.find('.qty').val();
price = roundNumber(price,2);
isNaN(price) ? row.find('.price').html("N/A") : row.find('.price').html("$"+price);
update_total();
}
function bind() {
$(".cost").blur(update_price);
$(".qty").blur(update_price);
}
$(document).ready(function() {
$('input').click(function(){
$(this).select();
});
$("#paid").blur(update_balance);
$("#addrow").click(function(){
$(".item-row:last").after('<tr class="item-row"><td class="item-name"><div class="delete-wpr"><SELECT NAME="edit_servicearea"><option>Select One<option>Air Intake<option>Brakes<option>Clutch<option>Cooling System<option>Driveshaft & Axle<option>Engine Mechanical<option>Exhaust<option>Steering<option>Suspension<option>Transmission<option>Other</select><a class="delete" href="javascript:;" title="Remove row">X</a></div></td><td class="description"><textarea>Description</textarea></td><td><textarea class="cost">$0</textarea></td><td><textarea class="qty">0</textarea></td><td><span class="price">$0</span></td></tr>');
if ($(".delete").length > 0) $(".delete").show();
bind();
});
$(".tax").blur(update_total);//binding tax
//bind();
bind();
.....
});
Again, here, my sales tax is highlighted in red. My problem specifically is that I'm unable to:
1.) get the sales tax rate to calculate based on the value of the subtotal, and
2.) on selection for including taxes, to bind the sale tax amount to the total.
I trust someone can provide some guidance!
Mossa