Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Looping through HTML (or INFRAGISTICS) elements...

    Hi guys,
    I am new around here so ... greetings!

    I've lately stepped up a little problem with one of my personal projects that i am working.

    I'm writing an aspx webpage, which includes web user controls inside it.

    The webuser controls are within a web form (id=form1 runat=server) which resides in the

    main.aspx page.

    1. First of all, is there a way to find a SPECIFIC control inside the webuser control (ascx)

    using Javascript in the main.aspx?

    2. If not (which i think it is), which is the best way to do it?
    The snippet i tried was this:

    '----------------------------------------------------
    function FindControl(elem_type,elem_id)
    {
    var elem = document.form1.elements;
    for(var i = 0; i < elem.length; i++)
    {

    if ((elem[i].type==elem_type) && (elem[i].id.indexOf(elem_id)!=-1))
    {
    alert(elem[i].id);
    }
    }
    }
    '----------------------------------------------------
    The problem is that the alerted id of the control isn't the exact id that i've written in the

    webuser control, but a string that seems to concatenate all the parent html controls of the

    control that i am searching for, ex. if the control that i'm searching for is
    <asp:Textbox id="txtName" runat="server"/> and it is nested inside a groupbox
    <groupbox:Group id="grp_1" runat="server"/> then the alerted id isn't TXTNAME but GRP_1_TXTNAME etc.
    Two questions then:
    1. Is the search in the "for statement" hierarchicly ordered? I mean, if i have another <asp:textbox id="txtName2" runat="server"/> inside the groupbox, will the first only be rendered if i put a break after the "if statement"?
    2. Is there a way to get the exact id name of the controls without the "indexOf"?

    Thanks in advance!

  • #2
    Regular Coder
    Join Date
    Jan 2006
    Posts
    568
    Thanks
    6
    Thanked 84 Times in 84 Posts
    Not sure I get it exactly, but

    Code:
    elem[i].id.substr(elem[i].id.lastIndexOf("_"))
    returns "TXTNAME" if elem[i].id is GRP_1_TXTNAME

    or it might be "_TXTNAME". Let me check that...

    Edit - yes it is, so

    Code:
    elem[i].id.substr(elem[i].id.lastIndexOf("_")+1)
    Last edited by gusblake; 12-15-2009 at 01:48 PM.

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    For javascript it does not matter the client-side code, but the HTML generated code. Show us the HTML generated code.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •