Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #17187
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Gregor Kofler <usenet@gregorkofler.com> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: JavaScript Case Project 3-1: The dreaded NaN error |
| Date | Mon, 12 Nov 2012 09:51:52 +0100 |
| Organization | A noiseless patient Spider |
| Lines | 41 |
| Message-ID | <k7qdb9$a45$1@dont-email.me> (permalink) |
| References | <055e7215-93ba-40a9-81f3-312ea0e4f5e2@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Mon, 12 Nov 2012 08:51:53 +0000 (UTC) |
| Injection-Info | mx04.eternal-september.org; posting-host="8704bf164e793a947cd84ce3d228347f"; logging-data="10373"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18DeLN50ktsxVXjObbVNuDUKzY7ut1qzmM=" |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121028 Thunderbird/16.0.2 |
| In-Reply-To | <055e7215-93ba-40a9-81f3-312ea0e4f5e2@googlegroups.com> |
| Cancel-Lock | sha1:scZcu5xv6tCRjbvjFLh3mgnaztk= |
| Xref | csiph.com comp.lang.javascript:17187 |
Show key headers only | View raw
Am 2012-11-11 17:28, dmn2004404@gmail.com meinte:
[snip]
> <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;
Should already throw an error (reference error), since txtPurchasePrice
is undefined at this point and txtPurchasePrice.value can't be evaluated.
> function calculateShipping() {
Something like
var purchasePrice =
parseFloat(document.forms["form1"].elements["txtPurchasePrice"].value)
*in* the function should do the trick.
(Multiplying a "float-like" string with a float will also result in a
float).
> if (purchasePrice <= 25)
> shippingAndHandling = 1.50;
> else
> shippingAndHandling = purchasePrice * .10;
> totalCost = purchasePrice + shippingAndHandling;
> window.alert('Purchase price plus shipping and handling is $' + totalCost);
> }
> </script>
> </head>
> For the record, I've also tried changing "txtPurchasePrice.value" to "document.getElementById('txtPurchasePrice').value"
Depends *when* you try to reference the element.
Gregor
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