Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getElementsByName 1

Status
Not open for further replies.

VBmim

Programmer
Joined
Jun 25, 2001
Messages
361
Location
BE
Hello

I have built a website that is split up in 2 different frames (one top and other one bottom). I wondered how you could use getElementsByName in the top page (in the top frame) for elements that are in the bottom page (in the botton frame).

Greetz

VBMim
 
theElements = document.parent.bottomFrameName.getElementsByName("tagName")

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Hello!

Thanks for your fast response.

I am afraid that the line of code you are suggesting doesn't work.

(HoofdFrame is the name of by bottom frame, Col1 is the item I want to retrieve)

I have tried

document.parent.HoofdFrame.getElementsByName('Col1')

document.parentwindow.Frames("HoofdFrame").getElementsByName('Col1')

document.parentwindow.Frames(0).getElementsByName('Col1')

document.parentwindow.all("HoofdFrame").getElementsByName('Col1')


All of these didn't work (gave errors)

Greetz

Mim
 
ooppss....

use getElementByName

no "s" in Element....

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Sorry... have the same results without the 's'
 
damn - I must be half asleep....

there is

getElementsByTagName

or

getElementById

use the second one and use IDs on the elements

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Hmmmmm, still not getting success

document.parentWindow.Frames("HoofdFrame").getElementById('Col1'); --> error: Object doesn't know this property or method

document.parentWindow.HoofdFrame.getElementById('Col1') --> error: document.parentWindow.HoofdFrame is empty or is not an object

if I use getElementsByTagName I get the same errors...

I am calling these functions from the top page (in top frame)... Does this affect the situation at all?

Thanks for your time already

Greetz

Mim
 
Aha!!

after

cell = parent.HoofdFrame.document.getElementById('Col1');

the statements

alert(cell[0])

returns 'undefined'...

The element 'Col1' exists but is built dynamicly.
Let me explain further in detail...

The following code is the function in my bottom page which gets my data.
The function 'Voorraad' gets a table in HTML String. 'Col1' is one of the columns. All columns have both the 'name' property and the 'id' property set.

VoorraadDiv is a <Div> tag that is in the page...

Code:
function HaalGegevens()
{
rsFunc=RSGetASPObject(&quot;../ProjD/RSDealer.ASP&quot;);
IHTML = rsFunc.Voorraad(2003).return_value;
VoorraadDiv.innerHTML = IHTML;
}
 
Found!!!!

parent.HoofdFrame.document.getElementsByName('Col1');

is what I need...

In fact, this looks just like your suggestion, but without the 'document' in front of the statement...

:)

Thanks a lot for your help

VeryHappyNewbieMim
 
I just looked it up when you posted... You're getting the &quot;cell&quot; value correctly.

I don't know that you can load a column - never worked with entire columns at a time... if Voorraad is holding an HTML string, then the &quot;col1&quot; ID doesn't yet exist - the string needs to be parsed by the browser for the actual object to exist....

what are you trying to do?

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
I'll explain...

The table I am getting is an inventory values table.

The first column is the name of the affected product group, and the next column is the figures of last year's december. All following tables are januari, februari and so on...

The table is too long to fit the screen, so I was asked if it was possible to scroll the table, but to let the first two columns visible. (so scroll only the month-columns).

When I build my table, I calculate how much columns I can draw on my screen without having to scroll(with the function window.screen.availWidth I can get the available width of my screen, and from there I calculate).

From there I hide all columns that 'fall out of the screen' with the method getElementsByName.

For example: if my calculations say that 6 columns can be displayed:

for (var i=7; i<13; i++)
{
cells = document.getElementsByName(&quot;Col&quot; + i);
for (var j=0; j < cells.length; j++)
cells[j].style.display = 'none';
}
}

Done!

I just had to add two buttons (one Right, one Left) to scroll to the remaining columns

function Left()
{
cells = document.getElementsByName(&quot;Col1&quot;);
for (var j=0; j < cells.length; j++)
cells[j].style.display = 'none';

cells = document.getElementsByName(&quot;Col7&quot;);
for (var j=0; j < cells.length; j++)
cells[j].style.display = 'block';
}

Then I realised that, because my table was quite long, if I scrolled down my table, I couldn't see my scrolling buttons. So I wanted to put them in another frame so they could stay visible...

And there I am

Sigh... what an explanation!

:)


 
this help???

function Left()
{
cells = parent.HoofdFrame.document.getElementsByName(&quot;Col1&quot;);
for (var j=0; j < cells.length; j++)
cells[j].style.display = 'none';

cells = parent.HoofdFrame.document.getElementsByName(&quot;Col7&quot;);
for (var j=0; j < cells.length; j++)
cells[j].style.display = 'block';
}


Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Yup! It works like a charm
 
Awesome...

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top