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


Groups > comp.lang.javascript > #17412

Re: Problem w/ creating dynamic TR and its TDs

From Cezary Tomczyk <cezary.tomczyk@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: Problem w/ creating dynamic TR and its TDs
Date 2012-12-02 18:48 +0100
Organization Aioe.org NNTP Server
Message-ID <k9g4a1$54q$1@speranza.aioe.org> (permalink)
References <e4c1bc98-b6a5-4142-a7a7-3fff318a7057@l12g2000vbj.googlegroups.com> <k9e45v$d6v$1@speranza.aioe.org> <5462881.fXVs31Ce0e@PointedEars.de> <k9f0rg$ajv$1@speranza.aioe.org> <5551855.fYihAxhPQP@PointedEars.de>

Show all headers | View raw


W dniu 2012-12-02 16:11, Thomas 'PointedEars' Lahn pisze:
>> Cezary Tomczyk wrote:
[...]
>> I am refereeing to old IE bug described on
>> http://webbugtrack.blogspot.cz/2007/10/bug-235-createelement-is-broken-
>> in-ie.html.
>> Of course, problem with setting dynamically attribute "name" is only in
>> IE 7 and lower.
>
> I have not tested in IE 7.  However, I have created a testcase and tested in
> IE 6.0.2800.1106 on Wine XP SP1 (IEs4Linux):
>
> <http://PointedEars.de/scripts/test/dom/input-submit>

Nice test.

[...]
> As we have found out here (or was it in de.comp.lang.javascript?) years ago,
> a workaround is to add the control to the `elements' collection if it is not
> yet part of it:
>
>    var input = document.createElement("input");
>    var name = "foo";
>    input.name = name;
>    input.value = "bar";
>    form.appendChild(input);
>
>    /* workaround for IE < 8 */
>    if (typeof form.elements[name] == "undefined")
>    {
>      form.elements[name] = input;
>    }
>
> As you can see, a disadvantage of that approach is that you lose the
> collection functionality if there is already a control with the same name.
> If that is a problem, I think you will have to combine it with other
> approaches or refer to the new control by other means than the `elements'
> collection.  (But someone – Richard Cornford? – might have already provided
> a solution to that problem as well.)

Personally I do not care about IE7 and lower. Currently I am focusing on 
IE8 and higher. However, thanks for explanation.

[...]

>> I tried to use Object.keys many times, but seems that it is very slow.
>
> At least it is reliable and can be rather easily emulated (for enumerable
> properties) down to ES 3.

Yes, that's true.

>> See test: http://jsperf.com/loop-for-in-vs-object-keys-foreach/2
>>
>> And yes, I remember your opinion about those tests :-)
>
> Good.  You should also know that you are comparing apples and oranges here.

Maybe. It is just a overall test.

> A for-in statement is _not_ equivalent to either foreach (or the E4X `for
> each') or Object.keys().  By contrast, it iterates over own and *inherited*
> *enumerable* properties in *implementation-dependent* (in ES3, arbitrary)
> order; the iterator is the property name, not the property value.
>
> Object.keys() returns a reference to an Array of the names of all *own*
> enumerable properties (in the same implementation-dependent order as for
> for-in), and *only* those.  [Which is why if you want to emulate
> Object.keys() for enumerable properties, you have to use
> Object.prototype.hasOwnProperty() or emulations thereof.]

I agree with you. Just forgot to get only direct properties of object. I 
use:

"   [...]
for (key in params) {
     if (Object.prototype.hasOwnProperty.call(params, key)) {
     [...]
"

[...]
>> I can not be sure now (it was long time ago), but as I remember I did
>> this because <input> element had to be append somewhere to create
>> properly <input> element with "name" attribute.
>
> You misremember.

Yes, it's possible.

>> However, today is not necessary.
>
> It never was.

I have no reason to not believe you.

[...]
> Please trim your quotes.

Should be better now.

-- 
Cezary Tomczyk
http://www.ctomczyk.pl/

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Problem w/ creating dynamic TR and its TDs justaguy <lichunshen84@gmail.com> - 2012-12-01 15:17 -0800
  Re: Problem w/ creating dynamic TR and its TDs Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2012-12-02 00:34 +0100
    Re: Problem w/ creating dynamic TR and its TDs justaguy <lichunshen84@gmail.com> - 2012-12-01 17:06 -0800
    Re: Problem w/ creating dynamic TR and its TDs Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-02 03:46 +0100
      Re: Problem w/ creating dynamic TR and its TDs justaguy <lichunshen84@gmail.com> - 2012-12-01 19:27 -0800
        Re: Problem w/ creating dynamic TR and its TDs Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-03 22:53 +0100
      Re: Problem w/ creating dynamic TR and its TDs Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2012-12-02 08:43 +0100
        Re: Problem w/ creating dynamic TR and its TDs Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-02 16:11 +0100
          Re: Problem w/ creating dynamic TR and its TDs Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2012-12-02 18:48 +0100
            Re: Problem w/ creating dynamic TR and its TDs Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-02 19:35 +0100
              Re: Problem w/ creating dynamic TR and its TDs Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-02 19:39 +0100

csiph-web