473,395 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

problem with getElementsByName

Hi, I cannot figure out why everything from line

var elem = doc.getElementsByName('keywords')

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.getElementById('frameSearch');
var doc = frame.document;
var elem = doc.getElementsByName('keywords');
alert (elem.length);
Jul 14 '08 #1
1 2089
wrote on 14 jul 2008 in comp.lang.javascript:
Hi, I cannot figure out why everything from line

var elem = doc.getElementsByName('keywords')

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.getElementById('frameSearch');
var doc = frame.document;
var elem = doc.getElementsByName('keywords');
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.document.getElementById('frameSearch');
alert(myIFrame);
var elem = myIFrame.document.getElementsByName('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
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....
5
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
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...
7
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.