...

View Full Version : help with form counting



6arredja
01-31-2005, 06:56 PM
<html>
<head>
<script language=javascript>
function old()
{
x = document.buy.gameboyold.value;
y = document.buy.amount.value;
document.buy.amount.value=" ";
document.buy.amount.value= y+x;
}
</head>
<body>
<form name=buy>
<input type=checkbox name=gameboyold onClick="old()">
<input type=text value=0.00 size=5 name="amount">
</form>
</body>
</html>


This is supposed to show the dollar amount owed (20)
but it just writes out: 0.0020 and adds 20 every time it is clicked on help me!!!!!!!!

hemebond
01-31-2005, 08:13 PM
Well, first of all, gameboyold doesn't have a value. Second of all, amount has a text value, so you need to use parseInt() to retrieve the value as a number.

Badman3k
01-31-2005, 08:19 PM
Okay this is simple to solve, but I'm not sure what you want it to do.

From the code you supplied the only thing this would do is write 0.00ononononon...... adding on everytime you click the checkbox.

Is this supposed to write only 20 when the checkbox is checked and then clear the field when the checkbox is cleared?

6arredja
02-01-2005, 05:14 PM
yes it is

Badman3k
02-01-2005, 06:35 PM
The following will switch between 20 and 0 if the checkbox is checked and unchecked, respectively.



<html>
<head>
<script language="javascript">
function old(what)
{
document.buy.amount.value = what.checked?"20":"0.00";
}
</script>
</head>
<body>
<form name=buy>
<input type=checkbox name="gameboyold" onClick="old(this)" value="20">
<input type=text value="0.00" size=5 name="amount">
</form>
</body>
</html>


Hope that helps :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum