hi Danny,
I have an issue where i need to get to a particular element when i click on a menu button.It is working fine in IE but in firefox it doenst work.There is a literal to which i am binding data dynamically and i have assigned id's.When i click on menu, i pass id to javascript function to scroll down to that element which is dynamically bound to literal and i change back ground colours.But it doesnt work in FireFOX.
COULD YOU PLEASE HELP?When i try to capture the value of the element,like document .getElemnetById("a"),i get null.The literal is inside a div and literal to bound on runtime with data with Ids to which i ned to navigate.

<script type="text/javascript">
        function Scroll(theElement) {
            var selectedPosX = 0;
            var selectedPosY = 0;
            while (theElement != null) {
                selectedPosX += theElement.offsetLeft;
                selectedPosY += theElement.offsetTop;
                theElement = theElement.offsetParent;
            }
            window.scrollTo(selectedPosX, selectedPosY);

                }

function toggleBgColor(elem) {  
            var styleVal = elem.style;
            styleVal .backgroundColor = styleVal .backgroundColor ? "" : "Green";
        }

        </script>

on menu click-i have something like

<ul>
<li><a id="" href=javascript:Scroll(a);javascript:ScrollToElement(a);"></a></li>

a is the id of the dynamic content am setting up in literal.


could you please help me?

Recommended Answers

All 5 Replies

Happi,

Try alert([selectedPosX, selectedPosY]) after the while loop to see what is constructed.

I think you will find that in FF .offsetTop/.offsetLeft return eg. '100px', therefore += will perform string concatenation. If so, then parseInt() will fix it.

function Scroll(theElement) {
    while (theElement != null) {
        selectedPosX += parseInt(theElement.offsetLeft);
        selectedPosY += parseInt(theElement.offsetTop);
        theElement = theElement.offsetParent;
    }
    window.scrollTo(selectedPosX, selectedPosY);
}

Airshow

It doesnt work in FF.The reason being(I got it from error console in FF)-
1.GetSelectedItem is not defined
2.a is not defined.(It comes from thsi code-<ul><li><a id="" href=javascript:Scroll(a);javascript:ScrollToElement(a);"></a></li>)
It doesnt go to jaavscript itself but in IE its too good.
any idea?

Happi,

Thinking about this again, the usual way to scroll to a given point in a document is:

<h2>MENU</h2>
<a href="#itemA">Item A</a> | <a href="#itemB">Item B</a>
...
...
<a name="itemA"></a>
...
...
<a name="itemB"></a>
...
...

Is there some reason why you don't do it this way?

Airshow

The reason being dont want to postback.Want to handle it in javascript itself.could figure out of IE but FF is driving me crazy.Tried all my tricks but in vain.

Happi, what do you mean by postback?

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.