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


Groups > comp.lang.javascript > #28437

Re: Recursive function to find a node in the DOM

From "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it>
Newsgroups comp.lang.javascript
Subject Re: Recursive function to find a node in the DOM
Date 2015-07-15 13:36 +0200
Organization A noiseless patient Spider
Message-ID <mo5gf4$l2m$1@dont-email.me> (permalink)
References <mo53os$am9$1@dont-email.me> <5530725.v0RXNFEj4j@PointedEars.de>

Show all headers | View raw


Il 07/15/2015 11:59 AM, Thomas 'PointedEars' Lahn ha scritto:
>
> document.forms[…].elements[…] and getElementsByTagName(…) exist.  You do not
> need that function even for Netscape Navigator 2 (the fact aside that it
> would not work there as it is).
>

The idea was to have a very generalized function. It finds whatever 
<name> in whatever <container>, and is used in a series of web 
applications I wrote, so I'm not tied to a tagName nor I use it only for 
forms...

>
> If you can change the input[type="text"] into an input[type="file"], for
> security reasons the value of the control will be reset, and you cannot set
> the “value” property of an input[type="file"] for the same reason.  So this
> appears to be a futile exercise (other than to test the security fix).

I know of that. But it is not an exercise. The scenario here is: a user 
can post a message in a [kinda of] message system. Messages can have 
attachments. If the author wants to edit the message he posted, he may 
want to change the text or the attachment. So he has a button "change 
attachment", and the input showing the name of the actual attachment 
becomes a <file> to select another one and upload it. :-)

>
>> One strange thing is the way recursion is implemented in javascript: I
>> did not put the "return retval" statement at first, it seems unuseful,
>> and went crazy before discovering that it is needed.
>
> There is no “javascript”.

ECMA, ok, ECMA.

Of course you need a break condition to prevent
> infinite recursion; this has nothing to do with what you think would be
> “javascript”.

Well I only wanted to point out that in other languages (f.e. xbase, the 
main language I use - to write CGI's at present -) I would have written 
the very same function with no need to put a return statement there.

And the proper approach here is iteration (walking the
> document tree), not recursion; because the stack size and/or nesting level
> is limited (the Google Groups archive has test results), but an element’s
> nesting level within a document tree is not.
>

Yes, but all this stuff is server-side generated, so I am quite in 
control of the pages (they are small in size) and I must confess that I 
like very much the recursive approach - but I am aware of the stack 
growth and memory consumption it causes.

Dan
-- 
"Everybody should pay taxes with a smile"
I tried, but they want money.

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


Thread

Recursive function to find a node in the DOM "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-15 09:59 +0200
  Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-15 11:59 +0200
    Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-15 12:03 +0200
    Re: Recursive function to find a node in the DOM "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-15 13:36 +0200
      Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-19 12:27 +0200
        Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-19 12:34 +0200
        Re: Recursive function to find a node in the DOM "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-21 12:08 +0200
          Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-25 14:11 +0200
            Re: Recursive function to find a node in the DOM "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-25 21:22 +0200
              Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-27 16:12 +0200
    Re: Recursive function to find a node in the DOM "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-08-08 04:50 +0200
      Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-08-08 09:33 +0200
        Re: Recursive function to find a node in the DOM "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-08-12 00:48 +0200
          Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-08-12 01:18 +0200
            Re: Recursive function to find a node in the DOM "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-08-13 23:26 +0200
              Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-08-16 08:48 +0200
                Re: Recursive function to find a node in the DOM "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-08-20 02:11 +0200
  Re: Recursive function to find a node in the DOM Scott Sauyet <scott.sauyet@gmail.com> - 2015-07-18 15:59 -0700
    Re: Recursive function to find a node in the DOM "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-21 12:30 +0200
      Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-21 13:53 +0200
        Re: Recursive function to find a node in the DOM "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-21 14:51 +0200
          Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-21 16:05 +0200
            Re: Recursive function to find a node in the DOM "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-21 20:35 +0200
            Re: Recursive function to find a node in the DOM Scott Sauyet <scott.sauyet@gmail.com> - 2015-07-30 22:10 -0700
              Re: Recursive function to find a node in the DOM "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-08-06 10:07 +0200
                Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-08-06 20:15 +0200
                Re: Recursive function to find a node in the DOM "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-08-08 01:21 +0200
        Re: Recursive function to find a node in the DOM Scott Sauyet <scott.sauyet@gmail.com> - 2015-07-30 22:09 -0700
  Re: Recursive function to find a node in the DOM Denis McMahon <denismfmcmahon@gmail.com> - 2015-07-29 03:04 +0000
    Re: Recursive function to find a node in the DOM "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-08-06 10:20 +0200

csiph-web