Question : find textbox and start div underneath it

Good morning,
Ive written an ASPx application, and have a floating DIV which appears and hides when required. Problem is I cant set the DIVs position correctly.

From what I understand I set the DIVs position using absolute refrencing, and I can set it anywhere on the page, but I want it to appear just underneath a textbox, which is positioned floating left in another div which uses 40% of the available page width.

Is there a Javascript function which I can call on page load to say:-
         myFloatingDiv.left = getelementbyID('myTextbox').left;
         myFloatingDiv.top = getelementbyID('myTextbox').top + 40px; // So it floats underneath, not on top.

Thanks in advance!

Answer : find textbox and start div underneath it

A quick google gives me this for looking up an element's left and top properties:

========

function getElementLeft(Elem) {
      if (ns4) {
            var elem = getObjNN4(document, Elem);
            return elem.pageX;
      } else {
            var elem;
            if(document.getElementById) {
                  var elem = document.getElementById(Elem);
            } else if (document.all){
                  var elem = document.all[Elem];
            }
            xPos = elem.offsetLeft;
            tempEl = elem.offsetParent;
              while (tempEl != null) {
                    xPos += tempEl.offsetLeft;
                    tempEl = tempEl.offsetParent;
              }
            return xPos;
      }
}


function getElementTop(Elem) {
      if (ns4) {
            var elem = getObjNN4(document, Elem);
            return elem.pageY;
      } else {
            if(document.getElementById) {      
                  var elem = document.getElementById(Elem);
            } else if (document.all) {
                  var elem = document.all[Elem];
            }
            yPos = elem.offsetTop;
            tempEl = elem.offsetParent;
            while (tempEl != null) {
                    yPos += tempEl.offsetTop;
                    tempEl = tempEl.offsetParent;
              }
            return yPos;
      }
}

======

After that, you can set another element's position like so:

======

document.getElementById("movetext").style.left = pos1;
document.getElementById("movetext").style.top = pos2;
Random Solutions  
 
programming4us programming4us