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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text Box Calculation

Status
Not open for further replies.

mdr2271

Programmer
Sep 14, 2005
42
US
If I have a textbox with the name "txtQuantity" and another one with the name "txtCost" how can I automatically populate the box "txtTotalCost"?
 
Code:
<script type="text/css">

function popuplateTotal() {
   var quantity = document.forms["formName"].elements["txtQuantity"].value;
   var cost = document.forms["formName"].elements["txtCost"].value;
   document.forms["formName"].elements["txtTotalCost"].value = quantity * cost;
}

</script>

-kaht

How much you wanna make a bet I can throw a football over them mountains?
sheepico.jpg
 
I am probably missing something simple here, but the following code seems pretty clear and is not working:

<html>
<head>
<title>Untitled</title>
</head>
<script type="text/javascript">

function popuplateTotal() {
var quantity = document.forms["register"].elements["txtQuantity1"].value;
var cost = document.forms["register"].elements["txtCost1"].value;
document.forms["register"].elements["txtTotalCost1"].value = quantity * cost;
}

</script>

<body>
<form name="register">
<input type="text" name="txtQuantity1">
<br>
<input type="text" name="txtCost1" onChange="populateTotal();">
<br>
<input type="text" name="txtTotalCost1">
</form>



</body>
</html>
 
Perhaps looking at the error would give it away: "populateTotal is not defined" - which it is not.

You are calling a function with a different name to the one kaht provided you with.

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks for the correction Dan
[banghead][banghead][banghead]


I had a MTG tournament that night and my head wasn't exactly in my work.....

I lost the first round 1-2, but subsequent rounds looked like this: 2-0, 2-0, 2-0.

I ended up in 4th place, not too bad after being out for about 4 years.

-kaht

How much you wanna make a bet I can throw a football over them mountains?
sheepico.jpg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top