Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #17169
| Newsgroups | comp.lang.javascript |
|---|---|
| Date | 2012-11-11 09:34 -0800 |
| References | <055e7215-93ba-40a9-81f3-312ea0e4f5e2@googlegroups.com> <aga4cnF1f0vU1@mid.individual.net> |
| Message-ID | <f361ca82-911a-4f52-9132-3f0af5baf3ca@googlegroups.com> (permalink) |
| Subject | Re: JavaScript Case Project 3-1: The dreaded NaN error |
| From | dmn2004404@gmail.com |
On Sunday, November 11, 2012 11:08:42 AM UTC-6, Mel Smith wrote:
> where I'm going wrong?
>
>
>
> You must convert the text string input to a floating point number --
>
> probably using the parseFloat() function. See below
>
>
>
> -Mel Smith (one neophyte to another)
>
>
>
>
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
>
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
>
> <html xmlns="http://www.w3.org/1999/xhtml">
>
> <head>
>
> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
>
> <title>Untitled Document</title>
>
> <script type="text/javascript">
>
> var purchasePrice = txtPurchasePrice.value, shippingAndHandling, totalCost;
>
> function calculateShipping() {
>
>
>
> // in here you need to convert the txtPurchasePrice to a floating point
>
> numeric before
>
> // you can start your calculations. Perhaps like the following:
>
>
>
> purchasePrice =
>
> parseFloat(document.getElementById("txtPurchasePrice").value) ;
>
>
>
> if (purchasePrice <= 25)
>
> shippingAndHandling = 1.50;
>
> else
>
> shippingAndHandling = purchasePrice * .10;
>
> totalCost = purchasePrice + shippingAndHandling;
>
>
>
> // now you should format your totalCost to an appropriate number of
>
> digits below
>
>
>
> window.alert('Purchase price plus shipping and handling is $' + totalCost);
>
> }
>
> </script>
>
> </head>
>
>
>
> <body>
>
> Purchase price (no dollar signs):
>
> <form id="form1" method="post" action="">
>
> <p>
>
> <label for="txtPurchasePrice"></label>
>
> <input type="text" name="txtPurchasePrice" id="txtPurchasePrice" />
>
> <input type="submit" name="btnCalculate" id="btnCalculate"
>
> value="Calculate" onclick="calculateShipping()" />
>
> </p>
>
> </form>
>
> </body>
>
> </html>
>
>
>
> For the record, I've also tried changing "txtPurchasePrice.value" to
>
> "document.getElementById('txtPurchasePrice').value" and even
>
> "txtPurchasePrice.text", but none of what I'm doing appears to make any
>
> difference -- no matter which way I go, it still says NaN.
Sadly, I think I tried that, and it also failed.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
JavaScript Case Project 3-1: The dreaded NaN error dmn2004404@gmail.com - 2012-11-11 08:28 -0800
Re: JavaScript Case Project 3-1: The dreaded NaN error "Mel Smith" <med_cutout_syntel@aol.com> - 2012-11-11 10:08 -0700
Re: JavaScript Case Project 3-1: The dreaded NaN error dmn2004404@gmail.com - 2012-11-11 09:34 -0800
Re: JavaScript Case Project 3-1: The dreaded NaN error "Mel Smith" <med_cutout_syntel@aol.com> - 2012-11-11 10:56 -0700
Re: JavaScript Case Project 3-1: The dreaded NaN error dmn2004404@gmail.com - 2012-11-11 10:07 -0800
Re: JavaScript Case Project 3-1: The dreaded NaN error dmn2004404@gmail.com - 2012-11-11 10:52 -0800
Re: JavaScript Case Project 3-1: The dreaded NaN error JJ <jaejunks@glegooilma-swapit.com> - 2012-11-11 20:15 +0000
Re: JavaScript Case Project 3-1: The dreaded NaN error dmn2004404@gmail.com - 2012-11-11 12:45 -0800
Re: JavaScript Case Project 3-1: The dreaded NaN error JJ <jaejunks@glegooilma-swapit.com> - 2012-11-11 20:11 +0000
Re: JavaScript Case Project 3-1: The dreaded NaN error dmn2004404@gmail.com - 2012-11-11 12:15 -0800
Re: JavaScript Case Project 3-1: The dreaded NaN error Osmo Saarikumpu <osmo@weppipakki.com> - 2012-11-12 10:10 +0200
Re: JavaScript Case Project 3-1: The dreaded NaN error Gregor Kofler <usenet@gregorkofler.com> - 2012-11-12 09:51 +0100
Re: JavaScript Case Project 3-1: The dreaded NaN error Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-11-12 11:49 +0100
csiph-web