Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #12133 > unrolled thread

Cant use <input text as a numeric

Started by" Cal Who" <CalWhoNOSPAM@roadrunner.com>
First post2012-02-24 14:32 -0500
Last post2012-02-25 21:00 +0000
Articles 20 on this page of 32 — 9 participants

Back to article view | Back to comp.lang.javascript


Contents

  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

Page 1 of 2  [1] 2  Next page →


#12133 — Cant use <input text as a numeric

From" Cal Who" <CalWhoNOSPAM@roadrunner.com>
Date2012-02-24 14:32 -0500
SubjectCant use <input text as a numeric
Message-ID<ji8ok2$30o$1@dont-email.me>
In my script I have (I've simplified the code for this test)var tmpN = 
document.ScrabbleStopWatch.timeTotal;
intervalMilliSecAllowed = parseFloat(tmpN) In the HTML I have<input 
type="text" onkeypress="return isNumberKey(event)" value="60" 
name="timeTotal" />
During dbugging I see that tmpN has a value of "60"But parseFloat(tmpN) has 
a value of NaN.I've tried different things but I can't seem to use 
document.ScrabbleStopWatch.timeTotal as a number.What am I doing 
wrong??Thanks 

[toc] | [next] | [standalone]


#12134

From" Cal Who" <CalWhoNOSPAM@roadrunner.com>
Date2012-02-24 16:54 -0500
Message-ID<ji90vi$m4s$1@dont-email.me>
In reply to#12133
What happen to my CR's???
Here it is again.

 In my script I have (I've simplified the code for this test):
var tmpN =  document.ScrabbleStopWatch.timeTotal;
intervalMilliSecAllowed = parseFloat(tmpN)

In the HTML I have
<input  type="text" value="60"  name="timeTotal" />

During dbugging I see that tmpN has a value of "60"
But parseFloat(tmpN) has a value of NaN.

I've tried different things but I can't seem to use
 document.ScrabbleStopWatch.timeTotal as a numeral.

What am I doing  wrong??

Thanks


[toc] | [prev] | [next] | [standalone]


#12135

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2012-02-24 22:34 +0000
Message-ID<4f481090$0$4322$a8266bb1@newsreader.readnews.com>
In reply to#12134
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??

The string value of the field named "timeTotal" in the form named 
"ScrabbleStopWatch" might be read using:

var strval = document.ScrabbleStopWatch.timeTotal.value;

and to take this as a floatVal:

numv = floatVal(document.ScrabbleStopWatch.timeTotal.value);

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:

document.getElementById("element_id").value = "a string value";

var strval = document.getElementById("element_id").value;

var intval = parseInt(document.getElementById("element_id").value);

var floatval = parseFloat(document.getElementById("element_id").value);

etc etc

Rgds

Denis McMahon

[toc] | [prev] | [next] | [standalone]


#12136

From" Cal Who" <CalWhoNOSPAM@roadrunner.com>
Date2012-02-24 17:48 -0500
Message-ID<ji944q$8p3$1@dont-email.me>
In reply to#12135
"Denis McMahon" <denismfmcmahon@gmail.com> wrote in message 
news:4f481090$0$4322$a8266bb1@newsreader.readnews.com...
> 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??
>
> 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!

>
> 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.

>
> 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?
>
> document.getElementById("element_id").value = "a string value";
>
> var strval = document.getElementById("element_id").value;
>
> var intval = parseInt(document.getElementById("element_id").value);
>
> var floatval = parseFloat(document.getElementById("element_id").value);
>
> etc etc
>
> Rgds
>
> Denis McMahon

Thanks a lot 

[toc] | [prev] | [next] | [standalone]


#12137

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2012-02-25 00:33 +0100
Message-ID<2271012.FRqVoOGUtd@PointedEars.de>
In reply to#12136
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).

[toc] | [prev] | [next] | [standalone]


#12142

From" Cal Who" <CalWhoNOSPAM@roadrunner.com>
Date2012-02-24 20:14 -0500
Message-ID<ji9clr$oeh$1@dont-email.me>
In reply to#12137
 >
> However, the proper way to refer to the value of the control is
>
>  document.forms["ScrabbleStopWatch"].elements["timeTotal"].value

Does this work in IE and Firefox?

I've seen the getElementById used many times.
Is this the old way and what you show is now replacing it.
If so, why is the new way better?


Thanks 

[toc] | [prev] | [next] | [standalone]


#12152

From"Evertjan." <exjxw.hannivoort@interxnl.net>
Date2012-02-25 08:51 +0000
Message-ID<XnsA0046458823CFeejj99@194.109.133.133>
In reply to#12142
 Cal Who wrote on 25 feb 2012 in comp.lang.javascript:

>> However, the proper way to refer to the value of the control is
>>
>>  document.forms["ScrabbleStopWatch"].elements["timeTotal"].value
> 
> Does this work in IE and Firefox?

> I've seen the getElementById used many times.
> Is this the old way and what you show is now replacing it.
> If so, why is the new way better?

Please do not fixate on what is "better" in programming.

Both ways are standard and so cross-browser compatible.

===

IE allows document.aName where aName is the name of a form or another 
emenent. That is one of MS's serious mistakes, as it is not standard and 
even in IE leads to errors when is html-reserved and used, like the 
document.forms collection. 

===

document.forms["ScrabbleStopWatch"].elements["timeTotal"].value

can be written as 

document.forms.ScrabbleStopWatch.elements.timeTotal.value

which is ok, but

document.forms[3].elements["timeTotal"].value

is a bit dangerous, as the 4th form could later be shifted by you to 
another place, without you realizing the number should be changed.

===

In simple testing I use document.forms[0], to point to the first [and 
only] form, all the time.

===

Using this or this.form is nice:

<form onsubmit='alert(this.name+" to be submitted NOW.")' name='myForm'>
<input type='submit' onclick='alert(this.form.name+" submits shortly.")'>
</form>

especially if you use a common [to more forms or inputs] function:

<input onclick='myFunc(this)'>

===

document.getElementById() can always be used and is quite safe when you 
rmember an id must be unique in html.

===

btw, please sign with a nickname or preferably your own name on this NG, 
talking to and quoting anonimous is cumbersome.

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#12175

From" Cal Who" <CalWhoNOSPAM@roadrunner.com>
Date2012-02-25 09:25 -0500
Message-ID<jiar18$rmp$1@dont-email.me>
In reply to#12152
"Evertjan." <exjxw.hannivoort@interxnl.net> wrote in message 
news:XnsA0046458823CFeejj99@194.109.133.133...
> Cal Who wrote on 25 feb 2012 in comp.lang.javascript:
>
>>> However, the proper way to refer to the value of the control is
>>>
>>>  document.forms["ScrabbleStopWatch"].elements["timeTotal"].value
>>
>> Does this work in IE and Firefox?
>
>> I've seen the getElementById used many times.
>> Is this the old way and what you show is now replacing it.
>> If so, why is the new way better?
>
> Please do not fixate on what is "better" in programming.
>
> Both ways are standard and so cross-browser compatible.
>
> ===
>
> IE allows document.aName where aName is the name of a form or another
> emenent. That is one of MS's serious mistakes, as it is not standard and
> even in IE leads to errors when is html-reserved and used, like the
> document.forms collection.
>
> ===
>
> document.forms["ScrabbleStopWatch"].elements["timeTotal"].value
>
> can be written as
>
> document.forms.ScrabbleStopWatch.elements.timeTotal.value
>
> which is ok, but
>
> document.forms[3].elements["timeTotal"].value
>
> is a bit dangerous, as the 4th form could later be shifted by you to
> another place, without you realizing the number should be changed.
>
> ===
>
> In simple testing I use document.forms[0], to point to the first [and
> only] form, all the time.
>
> ===
>
> Using this or this.form is nice:
>
> <form onsubmit='alert(this.name+" to be submitted NOW.")' name='myForm'>
> <input type='submit' onclick='alert(this.form.name+" submits shortly.")'>
> </form>
>
> especially if you use a common [to more forms or inputs] function:
>
> <input onclick='myFunc(this)'>
>
> ===
>
> document.getElementById() can always be used and is quite safe when you
> rmember an id must be unique in html.
>
> ===
>
> btw, please sign with a nickname or preferably your own name on this NG,
> talking to and quoting anonimous is cumbersome.
>
> -- 
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

Thanks
Cal 

[toc] | [prev] | [next] | [standalone]


#12216

FromGene Wirchenko <genew@ocis.net>
Date2012-02-27 13:49 -0800
Message-ID<lgunk7p817n3bqiap7ud9g9t9sdvkcsvqt@4ax.com>
In reply to#12152
On 25 Feb 2012 08:51:54 GMT, "Evertjan."
<exjxw.hannivoort@interxnl.net> wrote:

[snip]

>document.getElementById() can always be used and is quite safe when you 
>rmember an id must be unique in html.

     It does?

     ISTM that I have seen examples -- was it CSS? -- where an id was
used repeatedly to have an effect applied in more than one place.

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#12217

From"Evertjan." <exjxw.hannivoort@interxnl.net>
Date2012-02-27 22:06 +0000
Message-ID<XnsA006EAFCAA9B9eejj99@194.109.133.133>
In reply to#12216
Gene Wirchenko wrote on 27 feb 2012 in comp.lang.javascript:

>>document.getElementById() can always be used and is quite safe when you 
>>rmember an id must be unique in html.
> 
>      It does?
> 
>      ISTM that I have seen examples -- was it CSS? -- where an id was
> used repeatedly to have an effect applied in more than one place.

YES it does, it must be unique.

A specific id is only allowed one per page.

Some browsers may be so forgiving when you breach this rule, that only the 
first instance of the erroneous multiple is taken as a reference.

That does not mean it is allowed or good programming behavour!

I heve never seen that getElementById() references multiple html-elements.
Then it should suddenly act like a collection?
You don't believe that yourself, methinks.

Methinks you are confused with the action of getElementsByName()
[ that has ...Elements... with a final s ]

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#12221

FromGene Wirchenko <genew@ocis.net>
Date2012-02-27 17:00 -0800
Message-ID<at8ok7doujeoccivicjr76gsh4l7pgp01u@4ax.com>
In reply to#12217
On 27 Feb 2012 22:06:00 GMT, "Evertjan."
<exjxw.hannivoort@interxnl.net> wrote:

>Gene Wirchenko wrote on 27 feb 2012 in comp.lang.javascript:
>
>>>document.getElementById() can always be used and is quite safe when you 
>>>rmember an id must be unique in html.
>> 
>>      It does?
>> 
>>      ISTM that I have seen examples -- was it CSS? -- where an id was
>> used repeatedly to have an effect applied in more than one place.
>
>YES it does, it must be unique.
>
>A specific id is only allowed one per page.

     Could you please post a quality link?

>Some browsers may be so forgiving when you breach this rule, that only the 
>first instance of the erroneous multiple is taken as a reference.
>
>That does not mean it is allowed or good programming behavour!

     I am not arguing with you.  I do not know.

>I heve never seen that getElementById() references multiple html-elements.
>Then it should suddenly act like a collection?
>You don't believe that yourself, methinks.
>
>Methinks you are confused with the action of getElementsByName()
>[ that has ...Elements... with a final s ]

     I do not think that I am confused.  I am ignorant.  While I can
code some things very well in JavaScript, I am still learning
JavaScript and get tripped up on fine points.

     I use getElementsByName()[0] rather than getElementById(),
because of this ignorance.  (I code using unique name property
values.)

     Here is an example of using duplicate id values.  This is in
_Mastering JavaScript and JScript", Listing 18.3 (p. 638).  Yes, I
know that this book is over ten years old, but it is the best
non-trivial JavaScript book that I have gotten my hands on.

***** Start of Listing *****
<html>

<head>
  <title>Using the JSS ids property and ID attribute</title>
  <style type="text/javascript">
tags.BODY.backgroundColor="white";
tags.P.color="blue";
ids.WARNING.color="red";
  </style>
</head>

<body>
<p>This is the first paragraph.
It uses the redefined paragraph style.</p>
<p id="WARNING">This is the second paragraph.
It has its ID attribute set to WARNING.</p>
<p>This is the third paragraph.
It uses the redefined paragraph style.</p>
<h1>This is a normal H1 heading.</h1>
<h1 id="WARNING">This H1 heading uses the WARNING ID.</h1>
</body>

</html>
***** End of Listing *****

     I can see wanting to apply WARNING to a number of places in a
page.  If the above is wrong, what is the correct way to get this same
effect?

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#12228

FromJohn G Harris <john@nospam.demon.co.uk>
Date2012-02-28 10:46 +0000
Message-ID<6bfXhBDfCLTPFwoE@J.A830F0FF37FB96852AD08924D9443D28E23ED5CD>
In reply to#12221
On Mon, 27 Feb 2012 at 17:00:55, in comp.lang.javascript, Gene Wirchenko
wrote:
>On 27 Feb 2012 22:06:00 GMT, "Evertjan."
><exjxw.hannivoort@interxnl.net> wrote:

  <snip>
>>YES it does, it must be unique.
>>
>>A specific id is only allowed one per page.
>
>     Could you please post a quality link?
  <snip>

There is no higher quality than
  <http://www.w3.org/TR/html401/>

See
  <http://www.w3.org/TR/html401/struct/global.html#h-7.5.2>
where it says :

"7.5.2 Element identifiers: the id and class attributes

Attribute definitions

id = name [CS]
    This attribute assigns a name to an element. This name must be
unique in a document."

  John
-- 
John Harris

[toc] | [prev] | [next] | [standalone]


#12254

FromGene Wirchenko <genew@ocis.net>
Date2012-02-28 12:45 -0800
Message-ID<q2fqk7db3viqv85nd0hduoodh5hr8qugbb@4ax.com>
In reply to#12228
On Tue, 28 Feb 2012 10:46:55 +0000, John G Harris
<john@nospam.demon.co.uk> wrote:

[snip]

>"7.5.2 Element identifiers: the id and class attributes
>
>Attribute definitions
>
>id = name [CS]
>    This attribute assigns a name to an element. This name must be
>unique in a document."

     OK.

     So what about the example I posted?  How would you get the
equivalent in valid form?

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#12258

From"Evertjan." <exjxw.hannivoort@interxnl.net>
Date2012-02-28 23:33 +0000
Message-ID<XnsA0085A9AC5DCeejj99@194.109.133.133>
In reply to#12254
Gene Wirchenko wrote on 28 feb 2012 in comp.lang.javascript:

> On Tue, 28 Feb 2012 10:46:55 +0000, John G Harris
> <john@nospam.demon.co.uk> wrote:
> 
> [snip]
> 
>>"7.5.2 Element identifiers: the id and class attributes
>>
>>Attribute definitions
>>
>>id = name [CS]
>>    This attribute assigns a name to an element. This name must be
>>unique in a document."
> 
>      OK.
> 
>      So what about the example I posted?  How would you get the
> equivalent in valid form?


Cann't say as I don't want to use invalid code 
as a base for discussion of correct code.

If you want to address multiple html-elements as a collection, 
just name them the same, not id them.

=====================
<div name='a'>xxxxDIV</div>
<span name='a'>xxxxSPAN</span>
<b name='a'>xxxxB</b>

<script type='text/javascript'>

var collection = document.getElementsByName('a');

for (i=0;i<collection.length;i++) {
  var c = collection[i];
  alert(c.tagName + ': ' + c.firstChild.nodeValue);
};

</script>
=====================

Or you could fake an id-collection:

=====================
<div id='a0'>xxxxDIV</div>
<span id='a1'>xxxxSPAN</span>
<b id='a2'>xxxxB</b>

<script type='text/javascript'>

for (i=0;i<3;i++) {
  var c = document.getElementById('a' + i);
  alert(c.tagName + ': ' + c.firstChild.nodeValue);
};

</script>
=====================


-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#12263

FromGene Wirchenko <genew@ocis.net>
Date2012-02-28 17:04 -0800
Message-ID<v5uqk710tfcumi4uskv26pd91sha5ihoe4@4ax.com>
In reply to#12258
On 28 Feb 2012 23:33:27 GMT, "Evertjan."
<exjxw.hannivoort@interxnl.net> wrote:

>Gene Wirchenko wrote on 28 feb 2012 in comp.lang.javascript:

[snip]

>>      So what about the example I posted?  How would you get the
>> equivalent in valid form?

>Cann't say as I don't want to use invalid code 
>as a base for discussion of correct code.

     I know what the invalid code is intended to do.  I want to know
how to do that with correct code.

[snip]

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#12268

From"Evertjan." <exjxw.hannivoort@interxnl.net>
Date2012-02-29 09:11 +0000
Message-ID<XnsA008679A21F9Ceejj99@194.109.133.133>
In reply to#12263
Gene Wirchenko wrote on 29 feb 2012 in comp.lang.javascript:

> On 28 Feb 2012 23:33:27 GMT, "Evertjan."
> <exjxw.hannivoort@interxnl.net> wrote:
> 
>>Gene Wirchenko wrote on 28 feb 2012 in comp.lang.javascript:
> 
> [snip]
> 
>>>      So what about the example I posted?  How would you get the
>>> equivalent in valid form?
> 
>>Cann't say as I don't want to use invalid code 
>>as a base for discussion of correct code.
> 
>      I know what the invalid code is intended to do.  I want to know
> how to do that with correct code.

Quite so, Gene, you may know and want to,
but I don't want to discuss 
the proper [in your eyes proper] working of invalid code.

Methinks the specs disalowance of multiple element.id-s with the same value 
is not only required but logical.

Any id should be unique.

There are so many ways to collect multiple html-elements into a collection 
without needing non-unique id-s.

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#12308

FromGene Wirchenko <genew@ocis.net>
Date2012-02-29 14:07 -0800
Message-ID<488tk7deus0f057pvn5qpkv9fuccf60l1u@4ax.com>
In reply to#12268
On 29 Feb 2012 09:11:07 GMT, "Evertjan."
<exjxw.hannivoort@interxnl.net> wrote:

>Gene Wirchenko wrote on 29 feb 2012 in comp.lang.javascript:
>
>> On 28 Feb 2012 23:33:27 GMT, "Evertjan."
>> <exjxw.hannivoort@interxnl.net> wrote:
>> 
>>>Gene Wirchenko wrote on 28 feb 2012 in comp.lang.javascript:
>> 
>> [snip]
>> 
>>>>      So what about the example I posted?  How would you get the
>>>> equivalent in valid form?
>> 
>>>Cann't say as I don't want to use invalid code 
>>>as a base for discussion of correct code.
>> 
>>      I know what the invalid code is intended to do.  I want to know
>> how to do that with correct code.
>
>Quite so, Gene, you may know and want to,
>but I don't want to discuss 
>the proper [in your eyes proper] working of invalid code.

     Are you really that dense?

     It is obvious from the incorrect code what is intended that it
do.  I would like to do that same thing with correct code.

>Methinks the specs disalowance of multiple element.id-s with the same value 
>is not only required but logical.

     It is also logical to group things.  Unfortunately, this thing
with CSS seems to work on id values not being unique.  What is the
alternative code?

>Any id should be unique.
>
>There are so many ways to collect multiple html-elements into a collection 
>without needing non-unique id-s.

     What if you wish to stay within HTML?

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#12311

From"Evertjan." <exjxw.hannivoort@interxnl.net>
Date2012-02-29 22:23 +0000
Message-ID<XnsA008EE064E503eejj99@194.109.133.133>
In reply to#12308
Gene Wirchenko wrote on 29 feb 2012 in comp.lang.javascript:

> On 29 Feb 2012 09:11:07 GMT, "Evertjan."
> <exjxw.hannivoort@interxnl.net> wrote:
> 
>>Gene Wirchenko wrote on 29 feb 2012 in comp.lang.javascript:
>>
>>> On 28 Feb 2012 23:33:27 GMT, "Evertjan."
>>> <exjxw.hannivoort@interxnl.net> wrote:
>>> 
>>>>Gene Wirchenko wrote on 28 feb 2012 in comp.lang.javascript:
>>> 
>>> [snip]
>>> 
>>>>>      So what about the example I posted?  How would you get the
>>>>> equivalent in valid form?
>>> 
>>>>Cann't say as I don't want to use invalid code 
>>>>as a base for discussion of correct code.
>>> 
>>>      I know what the invalid code is intended to do.  I want to know
>>> how to do that with correct code.
>>
>>Quite so, Gene, you may know and want to,
>>but I don't want to discuss 
>>the proper [in your eyes proper] working of invalid code.
> 
>      Are you really that dense?

It is you that wants me to do something,
and insisting after I declined.

>      It is obvious from the incorrect code what is intended that it
> do.  I would like to do that same thing with correct code.

I do not read code marked as incorrect as a source to your intentions.
I am not your intended father in law.

>>Methinks the specs disalowance of multiple element.id-s with the same
>>value is not only required but logical.
> 
>      It is also logical to group things.  Unfortunately, this thing
> with CSS seems to work on id values not being unique.  What is the
> alternative code?

Pehaps some browsers are indulgent to your errors. But not in the way you 
described. Such browsers only reference the first of this same names id-
group. 

Believing that therefore it is a right and safe way to programme
is ludicrous.

Programming may be paved by good intentions indeed.
Experience and clear spec-knowledge are more important.

>>Any id should be unique.
>>
>>There are so many ways to collect multiple html-elements into a
>>collection without needing non-unique id-s.
> 
>      What if you wish to stay within HTML?

Meaning without css and javascript?

In html, id-referencing is only used in <label for='...'>,
I believe.



-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#12315

FromGene Wirchenko <genew@ocis.net>
Date2012-02-29 16:04 -0800
Message-ID<5petk75hf9dae7pd1c2itphieugp0j5rdt@4ax.com>
In reply to#12311
On 29 Feb 2012 22:23:59 GMT, "Evertjan."
<exjxw.hannivoort@interxnl.net> wrote:

[snip]

>It is you that wants me to do something,
>and insisting after I declined.

     You insist that there is a standard which there is, but provide
no guidance to how to code with the standard.  Not a very good answer,
then and hardly encouragement to use the standard.  My question is
clear enough.  I can try again:

     With CSS, you can define an override behaviour and invoke it with
id=.  How do you do this more than once in a document without running
afoul of that id values are supposed to be unique?

[snip]

>>      What if you wish to stay within HTML?
>
>Meaning without css and javascript?

     I was thinking of HTML with CSS.

>In html, id-referencing is only used in <label for='...'>,
>I believe.

     I can not think of another either.

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#12220

FromEric Bednarz <bednarz@fahr-zur-hoelle.org>
Date2012-02-28 01:58 +0100
Message-ID<m2ipirrcx8.fsf@nntp.bednarz.nl>
In reply to#12216
Gene Wirchenko <genew@ocis.net> writes:

>      ISTM that I have seen examples -- was it CSS? -- where an id was
> used repeatedly to have an effect applied in more than one place.

ISTM that I have seen examples – was it Colorado? – where communism worked.
    I haven’ t seen many examples of proper indenting of opening pragraphs,
or en dashes, though. :-)

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.javascript


csiph-web