Re: Form Values
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: Form Values

From: VK <schools_ring@yahoo.com>
Date: Thu Jul 21 2005 - 12:33:33 CEST

portchey wrote:
> I have a form that has many text boxes that the user enters the
> quantity of an item. Each item has a unit value.
> How do I display on the page the total value of each item next to each
> text box as the user enters the quantity in each text box in turn.

<html>
<head>
<title>Calculate</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script type="text/javascript">
function recalculate(goody) {
 var output = document.getElementById(goody.id+'total');
 var quantity = goody.value;
 if (!isNaN(parseInt(quantity,10))) {
  var price = goody.getAttribute('price');
  output.innerHTML = quantity*price;
 }
 else {
  output.innerHTML = 0;
 }
}
</script>
</head>

<body bgcolor="#FFFFFF">

<form name="myForm">
 <label for="item001">Item 1:</label>
 <input type="text" name="item001" id="item001"
  size="3" maxlength="3" value="0" price="25"
  onfocus="this.select();"
  onkeyup="recalculate(this);">
 <span>Total: $<span id="item001total">0</span></span>
</form>

</body>
</html>
Received on Tue Oct 18 02:59:07 2005