www.webdeveloper.com
Results 1 to 3 of 3

Thread: accessing document items

  1. #1
    Join Date
    May 2011
    Posts
    2

    accessing document items

    I am trying to access elements of one frame to another by doing the following:
    Code:
    function GetClientId(strid) {
            var i = 0;
            var eleName;
            var breakout = 0;
            for (j = 0; j < parent.right.document.forms.length; j++) {
                for (i = 0; i < parent.right.document.forms[j].length; i++) {
                    eleName = parent.right.document.forms[j].elements[i].id;
                    pos = eleName.indexOf(strid);
                    if (pos >= 0) {
                        breakout = 1;
                        break;
                    }
                }
            }
            if (breakout == 0) 
                eleName = "";
            return eleName;
        }
    But I have an asp page that is rendered in the frame with the following html and the <a> is not being picked up with the above code:
    HTML Code:
    <a id="ctl00_btnLogin" tabindex="3" class="button loginbutton" class="loginbutton" onkeypress="return WebForm_FireDefaultButton(event, 'ctl00_btnLogin');" href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$btnLogin&quot;, &quot;&quot;, true, &quot;LoginControl&quot;, &quot;&quot;, false, true))"><span>Log In</span></a>
    Why is this? Is it because <a> are not part of document.forms? More importantly how would I go through all html tags?

  2. #2
    Join Date
    May 2011
    Posts
    2

    Clarification

    I am loading a aspx page into a frame and trying to access that page's elements from another frame. To get the run-time created names, I am performing the code above.

  3. #3
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Yes, <A></A> is not an element of a form. In order to circle to all the HTML tags, you may use the method getElementsByTagName(), and a wild card "*"
    Code:
    var myFrame=parent.document.getElementsByName('framename')[0];
    var allElements=myFrame.contentWindow.document.getElementsByTagName('*');
    You may circle also trough oll the elements with a certain node (tag) name, let's say all the links and anchors:
    Code:
    getElementsByTagName('a')
    Last edited by Kor; 05-20-2011 at 07:55 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles