bcrooks
asked on
javascript calculation
I'm trying to have javascript calculate an amount when the user inputs a number.
<script type="text/JavaScript">
function Calculate()
{
var TextBox2 = parseInt(document.getEleme ntById('<% = numJazzPresident.ClientID% >').value) ;
var TextBox3 = parseInt(document.getEleme ntById('<% = numWinePaint.ClientID%>'). value);
var TextBox4 = parseInt(document.getEleme ntById('<% = numVariety.ClientID%>').va lue);
if (TextBox2 == " ") { var jazzDollar = 0; }
else { jazzDollar = (parseInt(TextBox2) * 20); }
if (TextBox3 == " ") { var wineDollar = 0; }
else { wineDollar = (parseInt(TextBox3) * 20); }
if (TextBox4 == " ") { var varietyDollar = 0; }
else { varietyDollar = (parseInt(TextBox4) * 10); }
document.getElementById('< %= TotalAmount.ClientID%>').v alue = alumniDollar + jazzDollar + wineDollar;
} </script>
html code
<asp:TextBox ID="numJazzPresident" onchange="return Calculate(this)" runat="server" Width="32px" ></asp:TextBox>
-------------------------- ---------- --------
the "totalAmount" textbox never gets updated
<script type="text/JavaScript">
function Calculate()
{
var TextBox2 = parseInt(document.getEleme
var TextBox3 = parseInt(document.getEleme
var TextBox4 = parseInt(document.getEleme
if (TextBox2 == " ") { var jazzDollar = 0; }
else { jazzDollar = (parseInt(TextBox2) * 20); }
if (TextBox3 == " ") { var wineDollar = 0; }
else { wineDollar = (parseInt(TextBox3) * 20); }
if (TextBox4 == " ") { var varietyDollar = 0; }
else { varietyDollar = (parseInt(TextBox4) * 10); }
document.getElementById('<
} </script>
html code
<asp:TextBox ID="numJazzPresident" onchange="return Calculate(this)" runat="server" Width="32px" ></asp:TextBox>
--------------------------
the "totalAmount" textbox never gets updated
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
There are a few things wrong with this code. You have undeclared variables and other variables that are declared but go out of scope before they are used in the final line of code.
Do the "empty" text boxes really contain a single space? Otherwise the comparison should be
if (TextBox4 == "")
ASKER
Thanks - its always the simple things
You are welcome