Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't get number to insert into text box 1

Status
Not open for further replies.

stephenbruceburch

Technical User
Jun 1, 2002
11
0
0
US

I'm trying to learn javascript and did an example from a book and I can't get it to work. It doesn't put the numbers back into the txtTotalTax and txtTotalCost text fields. And I don't know what I am doing wrong. It looks like the other examples and they all worked. Any help would be great appreciated.


<script language=&quot;javascript&quot;>
var intPrice, intTax, intTotalTax, intTotalCost;
function calculateJS(){
intPrice = document.frmJS.txtPrice.value;
intTax = document.frmJS.txtTax.value;
intTotalTax = intPrice * intTax;
document.frmJS.txtTotalTax = intTotalTax;
intTotalCost = (1 * intPrice + intTotalTax);
document.frmJS.txtTotalCost.value = intTotalCost;
}
</script>
<h3>Calculate the Tax</h3>
<form name=&quot;frmJS&quot;>
<input type=&quot;text&quot; name=&quot;txtPrice&quot; maxlength=&quot;7&quot;>
Product Price<br>
<input type=&quot;text&quot; name=&quot;txtTax&quot; value=&quot;.085&quot; maxlength=&quot;7&quot;>
Percent Tax (0.085)<br>
<input type=&quot;text&quot; name=&quot;txtTotalTax&quot; maxlength=&quot;7&quot;>
Total Tax in Dollars<br>
<input type=&quot;text&quot; name=&quot;txtTotalCost&quot; maxlength=&quot;7&quot;>
Total Cost of the Product<br>
<input type=&quot;button&quot; name=&quot;btnButton&quot; value=&quot;Calculate my Total&quot; onClick=&quot;calculateJS();&quot;>
</form>
 
here's an error:
document.frmJS.txtTotalTax.value = intTotalTax;

You can do the same with less operations and without all those vars:

function calculateJS() {

document.frmJS.txtTotalTax.value = document.frmJS.txtPrice.value * document.frmJS.txtTax.value;

document.frmJS.txtTotalCost.value = (1 * document.frmJS.txtPrice.value + document.frmJS.txtTotalTax.value);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top