problem with getElementsByName

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bbla32@op.pl

    problem with getElementsByName

    Hi, I cannot figure out why everything from line

    var elem = doc.getElements ByName('keyword s')

    in x.js is not executed. My goal is to set value of <input
    name=keywords ...which is in a.html after page is loaded.

    ------------------ search.html --------------------

    <html>
    <head>
    <title>Search </title>
    <script src="x.js"/>
    </head>

    <frameset rows="*" onload="load()" >
    <frame src="search-1.html"/>
    </frameset>

    </html>

    ------------------- search-1.html -------------------------

    <html>
    <head>
    <title>Search </title>
    </head>
    <body>

    <iframe src="a.html" height="600" width="600" id="frameSearch ">
    </iframe>

    </body>
    </html>

    ----------------- a.html --------------------------

    <html>
    <head>
    <title>Web Interface</title>
    </head>
    <body>
    <form action="submit" >
    <input type=text name=keywords size=40 value="">
    </form></html>

    -------------- x.js -------------------------------

    function load() {
    var frame = frames[1].document.getEl ementById('fram eSearch');
    var doc = frame.document;
    var elem = doc.getElements ByName('keyword s');
    alert (elem.length);
  • Evertjan.

    #2
    Re: problem with getElementsByNa me

    wrote on 14 jul 2008 in comp.lang.javas cript:
    Hi, I cannot figure out why everything from line
    >
    var elem = doc.getElements ByName('keyword s')
    >
    in x.js is not executed. My goal is to set value of <input
    name=keywords ...which is in a.html after page is loaded.
    >
    ------------------ search.html --------------------
    >
    <html>
    <head>
    <title>Search </title>
    <script src="x.js"/>
    </head>
    >
    <frameset rows="*" onload="load()" >
    <frame src="search-1.html"/>
    </frameset>
    >
    </html>
    >
    ------------------- search-1.html -------------------------
    >
    <html>
    <head>
    <title>Search </title>
    </head>
    <body>
    >
    <iframe src="a.html" height="600" width="600" id="frameSearch ">
    </iframe>
    >
    </body>
    </html>
    >
    ----------------- a.html --------------------------
    >
    <html>
    <head>
    <title>Web Interface</title>
    </head>
    <body>
    <form action="submit" >
    <input type=text name=keywords size=40 value="">
    </form></html>
    >
    -------------- x.js -------------------------------
    >
    function load() {
    var frame = frames[1].document.getEl ementById('fram eSearch');
    var doc = frame.document;
    var elem = doc.getElements ByName('keyword s');
    alert (elem.length);
    Treat frame as a reserved word, use myFrame or so.

    Methinks it is document.frames[0] not [1]

    The frame being loaded does not sigmal that the iframe is loaded.
    Better put some code in the iframe itself,
    or use a timeOut delay [not relyable, loading could be interupted].

    Extensive debugging will probably give you all the answers,
    delete or // the alert()s one by one to reveal any timing problems:


    <input name='keywords' value='myTest'>


    function load() {
    var myFrames = document.frames ;
    alert(myFrames) ;
    var myFrame = myFrames[0];
    alert(myFrame);
    var myIFrame = myFrame.documen t.getElementByI d('frameSearch' );
    alert(myIFrame) ;
    var elem = myIFrame.docume nt.getElementsB yName('keywords ');
    alert(elem);
    alert (elem.length);
    alert (elem[0]);
    alert (elem[0].value);
    };


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

    Comment

    Working...