By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,504 Members | 1,176 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,504 IT Pros & Developers. It's quick & easy.

anchors

P: n/a
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
Jul 20 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Ivo
"Ward" <ki************@for.president.com> wrote in message
news:Xn**********************************@195.130. 132.70...
<snip>
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
any suggestions ?
thx

Ward

Jul 20 '05 #2

P: n/a
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;

Jul 20 '05 #3

P: n/a
On Tue, 24 Feb 2004 13:57:47 GMT, Ward <ki************@for.president.com>
wrote:
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>
<tr id="frag-identifier">
<td>
...
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

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #4

P: n/a
Michael Winter <M.******@blueyonder.co.invalid> wrote in
news:op**************@news-text.blueyonder.co.uk:
On Tue, 24 Feb 2004 13:57:47 GMT, Ward
<ki************@for.president.com> wrote:
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>
<tr id="frag-identifier">
<td>
...
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
Jul 20 '05 #5

P: n/a
On Tue, 24 Feb 2004 21:45:02 GMT, Ward Germonpé
<ki**********@forpresident.com> wrote:
Michael Winter <M.******@blueyonder.co.invalid> wrote in
news:op**************@news-text.blueyonder.co.uk:
[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

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #6

P: n/a
Michael Winter <M.******@blueyonder.co.invalid> wrote in
news:op**************@news-text.blueyonder.co.uk:
On Tue, 24 Feb 2004 21:45:02 GMT, Ward Germonpé
<ki**********@forpresident.com> wrote:
Michael Winter <M.******@blueyonder.co.invalid> wrote in
news:op**************@news-text.blueyonder.co.uk:


[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
Jul 20 '05 #7

P: n/a
On Wed, 25 Feb 2004 10:18:27 GMT, Ward <ki************@for.president.com>
wrote:
Michael Winter <M.******@blueyonder.co.invalid> wrote in
news:op**************@news-text.blueyonder.co.uk:
On Tue, 24 Feb 2004 21:45:02 GMT, Ward Germonp
<ki**********@forpresident.com> wrote:
[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

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #8

P: n/a
Michael Winter <M.******@blueyonder.co.invalid> wrote in
news:op**************@news-text.blueyonder.co.uk:
On Wed, 25 Feb 2004 10:18:27 GMT, Ward
<ki************@for.president.com> wrote:
Michael Winter <M.******@blueyonder.co.invalid> wrote in
news:op**************@news-text.blueyonder.co.uk:
On Tue, 24 Feb 2004 21:45:02 GMT, Ward Germonp
<ki**********@forpresident.com> wrote:
[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
Jul 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.