/    Sign up×
Community /Pin to ProfileBookmark

Calc won’t work in Mozilla

Hi all,

I’m a little rusty on my JS and can’t get my simple tax calculator to work in Mozilla. I’m sure this is an easy one for you guys, so if you could offer some advice or a solution I’d be pretty psyched.

Here’s the code:

[CODE]
<!DOCTYPE HTML PUBLIC “-//W3C//Dtd HTML 4.01 transitional//EN”>
<html>
<head>
<title>Property Tax Calculator</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>

<SCRIPT language=”javascript”>
<!–
//clear all fields
function clearfields(){
frmAmount.value = “”;
frmCurrentBill.value = “”;
}

//format numbers to currency
function formatCurrency(num) {
num = num.toString().replace(/$|,/g,”);
if(isNaN(num))
num = “0”;
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = “0” + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+’,’+
num.substring(num.length-(4*i+3));
return (((sign)?”:’-‘) + num + ‘.’ + cents);
}

//alerts
function doTax(){

if(frmAmount.value==””){
alert(“Please enter your Home Value”);
return;
}
if(frmArea.value==””){
alert(“Please choose City or County”);
return;
}

var str = frmAmount.value;
var str2 = str.replace(/,/g,””);
frmAmount.value = str2;

//estimated annual property tax
currentArea = (frmAmount.value*.1)*frmArea.value;
if (currentArea < 0){
currentArea = 0;
}
currentTotal = currentArea;
frmCurrentBill.value = formatCurrency(currentTotal);
}
–>
</SCRIPT>
</head>

<body>
<div align=”center”>
<table width=”200″ border=”0″ cellspacing=”0″ cellpadding=”0″>
<tr>
<td><b><u><font face=”Arial, Helvetica, sans-serif”>Property Tax Calculator</font></u></b><br>
<br>
<table width=”200″ border=0 cellPadding=0 cellSpacing=0>
<tbody>
<tr>
<td width=”110″><font size=2 face=”Arial, Helvetica, sans-serif”>Home
Value:</font></td>
<td width=”90″><font size=”-1″ face=”Arial, Helvetica, sans-serif”>$</font>
<input size=”8″ name=”frmAmount” id=”frmAmount”></td>
</tr>
<tr>
<td width=”110″>&nbsp;</td>
<td width=”90″>&nbsp;</td>
</tr>
<tr>
<td width=”110″><font size=2 face=”Arial, Helvetica, sans-serif”>City
or County:</font></td>
<td width=”90″>&nbsp;&nbsp;&nbsp;<select name=”frmArea” id=”frmArea”>
<option selected>Select</option>
<!– enter tax rate here –>
<option value=”.0560″>City</option>
<option value=”.0400″>County</option>
</select></td>
</tr>
</tbody>
</table>
<br>
<input onclick=”doTax();” type=”button” value=”Calculate” name=”calculate” id=”calculate”>
<input onclick=”clearfields();” type=”reset” value=”Reset”>
<br>
<br>
<table width=”200″ border=”0″ cellspacing=”0″ cellpadding=”0″>
<tr>
<td width=”110″><font size=2 face=”Arial, Helvetica, sans-serif”>Estimated Annual Property
Tax:</font></td>
<td width=”90″ valign=”bottom”><font size=”-1″ face=”Arial, Helvetica, sans-serif”>$</font>
<input size=”8″ name=”frmCurrentBill”></td>
</tr>
</table> </td>
</tr>
</table>
</div>
</body>
</html>
[/CODE]

Thanks in advance for any help!

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@PittimannMay 18.2004 — Hi!

I would advise you to put your form fields in a form; after having done so, you will have to add "document.forms[0]." in front of the form fields' names inside your script. Example:

function clearfields(){

document.forms[0].frmAmount.value = "";

document.forms[0].frmCurrentBill.value = "";

}

Another way would be to reference the fields by their ids (after having assigned such an id to each relevant field). Example:

function clearfields(){

document.getElementById('id1GoesHere').value = "";

document.getElementById('id2GoesHere').value = "";

}

Cheers - Pit
Copy linkTweet thisAlerts:
@SuperfrappeauthorMay 18.2004 — Hey Pit!

Thanks for your help. So now when I test the page, the validation works, but I still can't get the calculation to work. At least with your help, I'm a little closer!

Here's what I've got now:

[CODE]
<!DOCTYPE HTML PUBLIC "-//W3C//Dtd HTML 4.01 transitional//EN">
<html>
<head>
<title>Property Tax Calculator</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<SCRIPT language="javascript">
<!--
//clear all fields
function clearfields(){
document.getElementById('frmAmount').value = "";
document.getElementById('frmCurrentBill').value = "";
}

//format numbers to currency
function formatCurrency(num) {
num = num.toString().replace(/$|,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + num + '.' + cents);
}

//alerts
function doTax(){

if(document.getElementById('frmAmount').value==""){
alert("Please enter your Home Value");
return;
}
if(document.getElementById('frmArea').value==""){
alert("Please choose City or County");
return;
}

var str = document.getElementById('frmAmount').value;
var str2 = str.replace(/,/g,"");
document.getElementById('frmAmount').value = str2;

//estimated annual property tax
currentArea = (document.getElementById('frmAmount').value*.1)*document.getElementById('frmArea').value;
if (currentArea < 0){
currentArea = 0;
}
currentTotal = currentArea;
document.getElementById('frmCurrentBill').value = formatCurrency(currentTotal);
}
-->
</SCRIPT>
</head>

<body>
<div align="center">
<table width="200" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><b><u><font face="Arial, Helvetica, sans-serif">Property Tax Calculator</font></u></b><br>
<br>
<table width="200" border=0 cellPadding=0 cellSpacing=0>
<tbody>
<tr>
<td width="110"><font size=2 face="Arial, Helvetica, sans-serif">Home
Value:</font></td>
<td width="90"><font size="-1" face="Arial, Helvetica, sans-serif">$</font>
<input size="8" name="frmAmount" id="frmAmount"></td>
</tr>
<tr>
<td width="110">&nbsp;</td>
<td width="90">&nbsp;</td>
</tr>
<tr>
<td width="110"><font size=2 face="Arial, Helvetica, sans-serif">City
or County:</font></td>
<td width="90">&nbsp;&nbsp;&nbsp;<select name="frmArea" id="frmArea">
<option selected>Select</option>
<!-- enter tax rate here -->
<option value=".0560">City</option>
<option value=".0400">County</option>
</select></td>
</tr>
</tbody>
</table>
<br>
<input onclick="doTax();" type="button" value="Calculate" name="calculate" id="calculate">
<input onclick="clearfields();" type="reset" value="Reset">
<br>
<br>
<table width="200" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="110"><font size=2 face="Arial, Helvetica, sans-serif">Estimated Annual Property
Tax:</font></td>
<td width="90" valign="bottom"><font size="-1" face="Arial, Helvetica, sans-serif">$</font>
<input size="8" name="frmCurrentBill"></td>
</tr>
</table> </td>
</tr>
</table>
</div>
</body>
</html>
[/CODE]



Do I need to assign more "document" ?

Thanks again! I'm learnin'!
Copy linkTweet thisAlerts:
@PittimannMay 18.2004 — Hi!

You just didn't assign an id to the last field:

<input size="8" name="frmCurrentBill">

Cheers - Pit
Copy linkTweet thisAlerts:
@SuperfrappeauthorMay 18.2004 — Pit -

Thanks again! It works! ?
Copy linkTweet thisAlerts:
@PittimannMay 18.2004 — Hi!

Nice! You're welcome! :p

Cheers - Pit
×

Success!

Help @Superfrappe spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...