473,837 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with getElementsByNa me

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);
Jul 14 '08 #1
1 2127
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)
Jul 14 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3362
by: adam | last post by:
i'm working on a portion of a CMS that allows content-admins to browse a product list, and add individual products into the taxonomy by clicking checkboxes next to categories they might belong in. since the taxonomy is a rather long list, i'm hiding and showing divs for the secondary and tertiary links, so when a user clicks on the checkbox for the parent category, the children appear in a second (and third) div, with checkboxes of their...
5
3695
by: simon | last post by:
<html> <head> <script language="vbscript"> sub window_onload msgbox document.getElementsByName("name1").length end sub </script> </head> <body> <div name="name1">testDiv</div>
22
7991
by: Saul | last post by:
I have a set of radio buttons that are created dynamically, after rendered I try loop thru this set by getting the length of the set, but I keep getting an error stating the element is undefined. I am using getElelementsByName since these are radio buttons, but it seems that the dynamic element is not seen!!! This is my code... please let me know if there is anything that I am doing wrong! - thanks ---- ....
7
374
by: lukaszmn | last post by:
Hi, I cannot figure out why everything from line "var elem = doc.getElementsByName('keywords')" in x.js is not executed. I want to set value of <input name=keywords ...which is in a.html after page is loaded. ------------------ search.html -------------------- <html> <head> <title>Search</title>
0
9844
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9683
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10883
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10578
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9409
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7006
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5851
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4477
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4049
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.