Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 12th, 2012, 04:13 PM
Authorized User
 
Join Date: Jun 2012
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Question Pls help - I'm new and my code crashes browser

Hello all,

I'm new here, and I'm trying to learn JavaScript. I'm working on an exercise where the user is supposed to enter several market values or enter 0 to quit. It uses a while loop, but it seems to be an infinite loop, and I can't see where the problem is. It crashes my browser. I really hope someone can help me. The code is posted below:

Code:
<html>
<head>
<title>The Evil Tax Collector</title>
<script language="JavaScript">

var marketValues = new Array();
var taxes = new Array();

function computeTax(market)
{
  var taxDetails = "";
  var assessedValue = market * 0.28;
  taxes[taxes.length] = assessedValue * 0.125;
  taxDetails = "The tax on the property with a market value of $" + market + " is $" + taxes[taxes.length];
  return taxDetails;
}


function printSummary()
{
  var i;
  var totalTax;

  for(i=0; i<taxes.length; i++)
  {
    totalTax += taxes[i];
  }
  document.taxForm.results.value = "The total taxes add up to $" + totalTax;
}


function processProperties()
{
  var marketTextbox = document.taxForm.txtMarket;
  var resultsTextbox = document.taxForm.results;

  while (marketTextbox.value != 0)
  {
    if(isNaN(marketTextbox.value) == true)
    {
      alert("Numbers only, please");
    }
    if (marketTextbox.value < 0)
    {
      alert("Positive numbers only, please");
    }
    marketValues[marketValues.length] = parseFloat(marketTextbox.value);
    resultsTextbox.value = computeTax(marketTextbox.value);
  }
  printSummary();
}

</script>
</head>
<body>
<h1>The Evil Tax Collector</h1>
<h2>Here to collect your soul!</h2>
Please enter a market value and click Submit.  To stop, enter 0 and then click Submit.<br><br>
<form name="taxForm">
Market Value: <input type="text" name="txtMarket"><br><br>
<input type="button" value="Submit" onclick="processProperties()">
<input type="reset" value="Nevermind"><br><br>
<input type="text" name="results">
</form>
</body>
</html>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro code crashes Excel 2007 pp1992 BOOK: Excel 2007 VBA Programmer's Reference ISBN: 978-0-470-04643-2 1 March 14th, 2010 05:56 PM
Pls Help Me Check This Code - Win32 ck C++ Programming 4 January 13th, 2005 12:14 AM
Pls Help Me Check This Code - Win32 ck Visual C++ 0 December 29th, 2004 12:50 PM
Pop Up Window crashes browser higgsy Javascript How-To 1 August 18th, 2003 03:32 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.