

// create an event handler that runs when they click on the calculate button

function calculate_click()
 {
 	 // get data from text boxes using their ID. Be sure to tell JS to convert string to floating number!
	 var mySubTotal = parseFloat(document.getElementById("txtSubTotal").value);
	 var myTaxRate = parseFloat(document.getElementById("txtTaxRate").value);
		 
	 
	 // do the math
	 var mySalesTax = mySubTotal * myTaxRate/100;
	 var mytotalDue = mySubTotal + mySalesTax;
	
	 // display results in the textboxes using these calculations and display with 2 decimals using toFixed(2) 
	 // note, toFixed will not work if your data is a string!!!!!
	 document.getElementById("txtSalesTax").value = mySalesTax.toFixed(2);
	 document.getElementById("txtTotal").value = mytotalDue.toFixed(2);
		 
 	 
 }
 

// when the document is loaded, associate the click event above with the button

function window.onload()
{
	 
	 //document.getElementById("btnCalculate").onclick = calculate_click;	//another way to wire up event handler
	 
	 document.getElementById("txtSubTotal").focus();	// set the focus/cursor to this textbox
}
