Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #12137
| Message-ID | <2271012.FRqVoOGUtd@PointedEars.de> (permalink) |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Organization | PointedEars Software (PES) |
| Date | 2012-02-25 00:33 +0100 |
| Subject | Re: Cant use <input text as a numeric |
| Newsgroups | comp.lang.javascript |
| References | <ji8ok2$30o$1@dont-email.me> <ji90vi$m4s$1@dont-email.me> <4f481090$0$4322$a8266bb1@newsreader.readnews.com> <ji944q$8p3$1@dont-email.me> |
| Followup-To | comp.lang.javascript |
Followups directed to: comp.lang.javascript
Cal Who wrote: > "Denis McMahon" wrote: >> On Fri, 24 Feb 2012 16:54:55 -0500, Cal Who wrote: >>> <input type="text" value="60" name="timeTotal" /> >> >>> [can't use] document.ScrabbleStopWatch.timeTotal as a numeral. >> >> This refers to the field. >> >>> What am I doing wrong?? You are attempting to convert an object to a number that has no built-in numeric representation. The parseFloat() function/method converts its argument to String (if necessary) before it parses it to a Number value (ECMAScript Language Specification, 5.1 Edition, section 15.1.2.3). Conversion to string may call (through ToPrimitive() and [[DefaultValue]]) an object's toString() method or valueOf() method, whichever can be found first (ibid., section 9.8). If a host object like a DOM object inherits from Object.prototype, then it inherits Object.prototype.toString(), which is specified to return "[object $CLASS]", where $CLASS is the value of the internal [[Class]] property of the object. In this case, in most cases the value of the [[Class]] property will be the identifier of the W3C DOM interface that the object implements, so "HTMLInputElement" here. And "[object HTMLInputElement]" cannot be parsed into a Number value by parseFloat(). Likewise, in the MSHTML DOM the string representation of a host object may be "[object]", for which the same applies. >> The string value of the field named "timeTotal" in the form named >> "ScrabbleStopWatch" might be read using: >> >> var strval = document.ScrabbleStopWatch.timeTotal.value; > Thanks, that did it! However, the proper way to refer to the value of the control is document.forms["ScrabbleStopWatch"].elements["timeTotal"].value whereas document.forms["ScrabbleStopWatch"] can be replaced with a shorter reference, such as `this' in an event-handler attribute value of the `form' element in question, and `this.form' in an event-handler attribute of the control in question; respectively, `o.form' in a function called from the latter event-handler attribute, if `o' is a function argument for which `this' is passed from the calling context. <https://developer.mozilla.org/en/DOM/document#Properties> pp. >> and to take this as a floatVal: >> >> numv = floatVal(document.ScrabbleStopWatch.timeTotal.value); > Is floatVal exactly the same as parseFloat? > I notice you used parseFloat below. There is no built-in floatVal() function in any sufficiently distributed ECMAScript implementation. There is a floatval() function in PHP which but does the same as parseFloat() in ECMAScript implementations. <https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/parseFloat> <http://php.net/floatval> >> But the more common way these days is to not use a form if you're not >> actually submitting the form data in a request, rather assign each field >> an id value and: > Do you neam - not use a <form> at all unless there is an element that > causes a form submit like --- for example, what? A `form' element can be useful for referring to other controls even if the form is never submitted. However, using a `form' element enables control's values to be submitted even if client-side scripting is unavailable. You would be well-advised not to learn from wannabes like Dennis McMahon, unless you would want to learn by bad example. PointedEars -- When all you know is jQuery, every problem looks $(olvable).
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Cant use <input text as a numeric " Cal Who" <CalWhoNOSPAM@roadrunner.com> - 2012-02-24 14:32 -0500
Re: Cant use <input text as a numeric " Cal Who" <CalWhoNOSPAM@roadrunner.com> - 2012-02-24 16:54 -0500
Re: Cant use <input text as a numeric Denis McMahon <denismfmcmahon@gmail.com> - 2012-02-24 22:34 +0000
Re: Cant use <input text as a numeric " Cal Who" <CalWhoNOSPAM@roadrunner.com> - 2012-02-24 17:48 -0500
Re: Cant use <input text as a numeric Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-25 00:33 +0100
Re: Cant use <input text as a numeric " Cal Who" <CalWhoNOSPAM@roadrunner.com> - 2012-02-24 20:14 -0500
Re: Cant use <input text as a numeric "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-02-25 08:51 +0000
Re: Cant use <input text as a numeric " Cal Who" <CalWhoNOSPAM@roadrunner.com> - 2012-02-25 09:25 -0500
Re: Cant use <input text as a numeric Gene Wirchenko <genew@ocis.net> - 2012-02-27 13:49 -0800
Re: Cant use <input text as a numeric "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-02-27 22:06 +0000
Re: Cant use <input text as a numeric Gene Wirchenko <genew@ocis.net> - 2012-02-27 17:00 -0800
Re: Cant use <input text as a numeric John G Harris <john@nospam.demon.co.uk> - 2012-02-28 10:46 +0000
Re: Cant use <input text as a numeric Gene Wirchenko <genew@ocis.net> - 2012-02-28 12:45 -0800
Re: Cant use <input text as a numeric "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-02-28 23:33 +0000
Re: Cant use <input text as a numeric Gene Wirchenko <genew@ocis.net> - 2012-02-28 17:04 -0800
Re: Cant use <input text as a numeric "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-02-29 09:11 +0000
Re: Cant use <input text as a numeric Gene Wirchenko <genew@ocis.net> - 2012-02-29 14:07 -0800
Re: Cant use <input text as a numeric "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-02-29 22:23 +0000
Re: Cant use <input text as a numeric Gene Wirchenko <genew@ocis.net> - 2012-02-29 16:04 -0800
Re: Cant use <input text as a numeric Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2012-02-28 01:58 +0100
Re: Cant use <input text as a numeric Gene Wirchenko <genew@ocis.net> - 2012-02-27 21:31 -0800
Re: Cant use <input text as a numeric Dr J R Stockton <reply1209@merlyn.demon.co.uk> - 2012-02-28 21:41 +0000
Re: Cant use <input text as a numeric Dr J R Stockton <reply1209@merlyn.demon.co.uk> - 2012-03-01 20:52 +0000
Re: Cant use <input text as a numeric Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-25 13:12 +0100
Re: Cant use <input text as a numeric Denis McMahon <denismfmcmahon@gmail.com> - 2012-02-25 04:36 +0000
Re: Cant use <input text as a numeric " Cal Who" <CalWhoNOSPAM@roadrunner.com> - 2012-02-25 09:13 -0500
Re: Cant use <input text as a numeric Denis McMahon <denismfmcmahon@gmail.com> - 2012-02-25 04:41 +0000
Re: Cant use <input text as a numeric Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-25 13:13 +0100
Re: Cant use <input text as a numeric " Cal Who" <CalWhoNOSPAM@roadrunner.com> - 2012-02-25 09:17 -0500
[OT] Quoting style (was: Cant use <input text as a numeric) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-27 17:52 +0100
Re: Cant use <input text as a numeric " Cal Who" <CalWhoNOSPAM@roadrunner.com> - 2012-02-25 09:15 -0500
Re: Cant use <input text as a numeric Dr J R Stockton <reply1208@merlyn.demon.co.uk> - 2012-02-25 21:00 +0000
csiph-web