Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder1.news.weretis.net!news-peer.in.tum.de!news.belwue.de!newsfeed.ision.net!newsfeed2.easynews.net!ision!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="ISO-8859-1" Message-ID: <2271012.FRqVoOGUtd@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Sat, 25 Feb 2012 00:33:41 +0100 User-Agent: KNode/4.4.11 Content-Transfer-Encoding: 7Bit Subject: Re: Cant use <4f481090$0$4322$a8266bb1@newsreader.readnews.com> Followup-To: comp.lang.javascript MIME-Version: 1.0 Lines: 82 NNTP-Posting-Date: 25 Feb 2012 00:33:41 CET NNTP-Posting-Host: 95dbae9f.newsspool2.arcor-online.net X-Trace: DXC=<loFInj\7Wa8Q0@ X-Complaints-To: usenet-abuse@arcor.de Xref: x330-a1.tempe.blueboxinc.net comp.lang.javascript:12137 Cal Who wrote: > "Denis McMahon" wrote: >> On Fri, 24 Feb 2012 16:54:55 -0500, Cal Who wrote: >>> >> >>> [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. 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. >> 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
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).