Re: Problem with javascript in web page.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Thanks David
I'll see what I can do with a few changes.
Are you saying that
<p class="links"><a onclick="toggle ('more');return false;"
href="#part2">Read More</a></p>
should be
<p class="links"><a onclick="toggle ('more')" href="#part2">Read
More</a></p>
Thanks for the help
"David Mark" <dmark.cinsoft@xxxxxxxxx> wrote in message
news:1192312728.298794.178550@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Oct 13, 4:56 pm, "BD" <n...@xxxxxxxxxxx> wrote:
I'm can't get this to work the way I want it to.
I have divs that are hidden by using style="display:none"
I have this javascript function in the head
<script language="javascript">
function toggle(element)
{
if (document.layers)
{
current = (document.layers[element].display == 'none') ? 'block' :
'none';
document.layers[element].display = current;
}

You can safely delete this first clause. If you really feel you must
try to support NS4, move this test to the end.

else if (document.all)
{
current = (document.all[element].style.display == 'none') ? 'block' :
'none';
document.all[element].style.display = current;
}

Similarly, this test should come after the test for
document.getElementById.

else if (document.getElementById)
{
vista = (document.getElementById(element).style.display == 'none') ?
'block' : 'none';
document.getElementById(element).style.display = vista;
}}

</script>
It works fine for toggleing the div but here comes the problem
The first line in the div is a bookmark. I want it to not only toggle
the
div but I want it to behave the same as a normal call to a bookmark
behaves
and that is by moving the div to the top of the page. The following call
won't do it.
<p class="links"><a onclick="toggle ('more');return false;"
href="#part2">Read More</a></p>
It toggles the div (more) OK but it does not move the bookmark (#part2)
to
the top of the page
The same applies when hiding the div (more)
<p class="links"><a onclick="toggle ('more');return false;"
href="#top">Close this section</a></p>
This will toggle fine but it does not jump to the very top of the page
(bookmarked as top)
What am I doing wrong here.

Returning valse cancels the default action.



.



Relevant Pages

  • Problem with javascript in web page.
    ... I have this javascript function in the head ... The first line in the div is a bookmark. ... This will toggle fine but it does not jump to the very top of the page ...
    (microsoft.public.scripting.jscript)
  • Re: Problem with javascript in web page.
    ... You can safely delete this first clause. ... The first line in the div is a bookmark. ... This will toggle fine but it does not jump to the very top of the page ...
    (microsoft.public.scripting.jscript)
  • Re: toggle text in different locations on the same page
    ... have only really dabbled in javascript. ... I have a working text toggle in place on a web page. ... Not here as the inherited default style for a DIV ... the link is cancelled by returning false from the onclick handler (or ...
    (comp.lang.javascript)
  • Re: show hide divs - show last state upon reload/post
    ... The toggle works fine, although when I click on submit, I ... If the div was ... When you post a form in a window in a frameset, only that window is refreshed, not the window holding the frameset definition. ...
    (comp.lang.javascript)
  • Re: window.location.replace bug
    ... the code is in the onclick() event. ... We have a scrolling DIV in an html page. ... When you click a link to a bookmark in the DIV, ...
    (microsoft.public.scripting.jscript)