anchors

W

Ward

Hi,

I have a topframe and a mainframe.

The topframe contains a listbox with trucknumbers (non sequential).
The mainframe contains a page, where each truck has a table with data.
In the topleft cell of each table I put a named link <a name=$trucknumber>.
Tables are generated using php.

I want to use an onChange event in the listbox to jump to the corresponding
anchor in the mainframe. The function below doesn't work.

function jump(anker){
parent.frames['main'].href="#"+parent.frames['main'].links[anker].value;
}

any suggestions ?


thx

Ward
 
L

Lee

Ward said:
Hi,

I have a topframe and a mainframe.

The topframe contains a listbox with trucknumbers (non sequential).
The mainframe contains a page, where each truck has a table with data.
In the topleft cell of each table I put a named link <a name=$trucknumber>.
Tables are generated using php.

I want to use an onChange event in the listbox to jump to the corresponding
anchor in the mainframe. The function below doesn't work.

function jump(anker){
parent.frames['main'].href="#"+parent.frames['main'].links[anker].value;

parent.frames['main'].location.hash="#"+truckNumber;
 
I

Ivo

function jump(anker){
parent.frames['main'].href="#"+parent.frames['main'].links[anker].value;
}

Have you also tried the variant with "location." just before "href." ?
HTH
Ivo
 
M

Michael Winter

The topframe contains a listbox with trucknumbers (non sequential).
The mainframe contains a page, where each truck has a table with data.
In the topleft cell of each table I put a named link
<a name=$trucknumber>.

New webpages should target sections within documents using the id
attribute instead of using A elements as anchors. So, in place of:

<table>
<tr>
<td><a name="frag-identifier"></a>
...

you might use:

<table>
I want to use an onChange event in the listbox to jump to the
corresponding anchor in the mainframe. The function below
doesn't work.

function jump(anker){
parent.frames['main'].href="#"+parent.frames['main'].links[anker].value;
}

any suggestions ?

1) Window objects, and therefore frames, do not have a href property.
2) ...nor do they have a links property.
3) Knowing what 'anker' is would be helpful.

The approach you have presented seems likely to fail in all browsers. Even
after correcting the l-value to use location, not href, it will still fail
in most browsers.

A simpler solution would be:

function changePage( linkList ) {
var fragment = linkList.options[ linkList.selectedValue ].value;

// Check that the option does contain a fragment identifier
// This allows for options such as "Choose section" which should
// have no destination
if( fragment ) parent.frames['main'].location = '#' + fragment;
}
...
<select onchange="changePage(this)">
<option value="">Choose section</option>
<option value="Section-1">Section 1</option>
<option value="Section-2">Section 2</option>
...
</select>

Mike
 
W

Ward Germonpé

The topframe contains a listbox with trucknumbers (non sequential).
The mainframe contains a page, where each truck has a table with
data. In the topleft cell of each table I put a named link
<a name=$trucknumber>.

New webpages should target sections within documents using the id
attribute instead of using A elements as anchors. So, in place of:

<table>
<tr>
<td><a name="frag-identifier"></a>
...

you might use:

<table>
I want to use an onChange event in the listbox to jump to the
corresponding anchor in the mainframe. The function below
doesn't work.

function jump(anker){
parent.frames['main'].href="#"+parent.frames['main'].links[anker].valu
e; }

any suggestions ?

1) Window objects, and therefore frames, do not have a href property.
2) ...nor do they have a links property.
3) Knowing what 'anker' is would be helpful.

The approach you have presented seems likely to fail in all browsers.
Even after correcting the l-value to use location, not href, it will
still fail in most browsers.

A simpler solution would be:

function changePage( linkList ) {
var fragment = linkList.options[ linkList.selectedValue ].value;

// Check that the option does contain a fragment identifier
// This allows for options such as "Choose section" which should
// have no destination
if( fragment ) parent.frames['main'].location = '#' + fragment;
}
...
<select onchange="changePage(this)">
<option value="">Choose section</option>
<option value="Section-1">Section 1</option>
<option value="Section-2">Section 2</option>
...
</select>

Mike

If you change selectedValue to selectedIndex your example does indeed
work.

thx for your help

Ward
 
M

Michael Winter

[snip]
function changePage( linkList ) {
var fragment = linkList.options[ linkList.selectedValue ].value;
[snip]

If you change selectedValue to selectedIndex your example does indeed
work.

Sorry. :) Lapse in concentration.

Mike
 
W

Ward

[snip]
function changePage( linkList ) {
var fragment = linkList.options[ linkList.selectedValue ].value;
[snip]

If you change selectedValue to selectedIndex your example does indeed
work.

Sorry. :) Lapse in concentration.

Mike

I'm not quite there yet...

I had to change the code as follows to prevent the topframe from loading
into the mainframe.

if (fragment) parent.frames['main'].location = parent.frames
['main'].location + '#' + fragment;

Now it works, but only once.

There are no errors in the javascript console.


thx

Ward
 
M

Michael Winter

[snip]
Sorry. :) Lapse in concentration.

I'm not quite there yet...

I had to change the code as follows to prevent the topframe from loading
into the mainframe.

if (fragment) parent.frames['main'].location = parent.frames
['main'].location + '#' + fragment;

Now it works, but only once.

There are no errors in the javascript console.

That is because a second usage will append, not replace, the first
fragment identifier. That is,

index.html -> index.html#Section-1 -> index.html#Section-1#Section-2

Lee's use of Location.hash should fix this:

if (fragment) parent.frames['main'].location.hash = '#' +
fragment;

Hopefully, that should be it.

Mike
 
W

Ward

[snip]
If you change selectedValue to selectedIndex your example does
indeed work.

Sorry. :) Lapse in concentration.

I'm not quite there yet...

I had to change the code as follows to prevent the topframe from
loading into the mainframe.

if (fragment) parent.frames['main'].location = parent.frames
['main'].location + '#' + fragment;

Now it works, but only once.

There are no errors in the javascript console.

That is because a second usage will append, not replace, the first
fragment identifier. That is,

index.html -> index.html#Section-1 ->
index.html#Section-1#Section-2

Lee's use of Location.hash should fix this:

if (fragment) parent.frames['main'].location.hash = '#' +
fragment;

Hopefully, that should be it.

Mike

It works !

thx a lot

Ward
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top