Recursively Find a Control?

Discussion in 'Javascript' started by bradwiseathome@hotmail.com, Mar 17, 2005.

  1. Guest

    I have some web-server-side code that may place a textbox anywhere on a
    page. It might be on the page itself, it might be within a <form>, it
    might be within a <div> in the form, or in a <div> inside the first
    <div>.

    Is there a script out there that will let me, given just the control's
    ID, recursively find it anywhere on the page so I can set focus to it?

    Any pointers appreciated - this is making me nuts!

    Thanks.
     
    , Mar 17, 2005
    #1
    1. Advertising

  2. RobB Guest

    wrote:
    > I have some web-server-side code that may place a textbox anywhere on

    a
    > page. It might be on the page itself, it might be within a <form>, it
    > might be within a <div> in the form, or in a <div> inside the first
    > <div>.
    >
    > Is there a script out there that will let me, given just the

    control's
    > ID, recursively find it anywhere on the page so I can set focus to

    it?
    >
    > Any pointers appreciated - this is making me nuts!
    >
    > Thanks.


    They made DOM a little easier than that...

    var el = null;
    if (document.getElementById)
    el = document.getElementById('box_id');
    else if (document.all)
    el = document.all['box_id'];
    if (el && el.focus)
    el.focus();

    Make sure to wait till the page is fully loaded.
     
    RobB, Mar 17, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark
    Replies:
    9
    Views:
    5,112
  2. Wybo Dekker
    Replies:
    1
    Views:
    379
    Yukihiro Matsumoto
    Nov 15, 2005
  3. Replies:
    17
    Views:
    1,369
    Eric J. Roode
    Nov 12, 2005
  4. vdvorkin
    Replies:
    0
    Views:
    424
    vdvorkin
    Feb 10, 2011
  5. vdvorkin
    Replies:
    3
    Views:
    832
    vdvorkin
    Feb 14, 2011
Loading...

Share This Page