How to get the Absolute position of an HTML form Control Element using JavaScript?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ahmednawazbutt
    New Member
    • Apr 2013
    • 1

    How to get the Absolute position of an HTML form Control Element using JavaScript?

    I have an .htm page wwhich consits of a frame with 0 border,width and height

    Now, when I enter a key,i.e onkeyup (keyboard pressing)event occurs, the form is submitted to asp.net page, which retrieves information and stores in a varriable.I use that asp.net varriable and using javascript in my .htm page and it works fine.

    the Problem is that i want my data to be displayed right below the html textbox no matter what type of screen resolution is and regadless of what type of screen size, user is keeping in use.

    as like below sketch

    -----------------------------------------
    Any Data that is written
    -----------------------------------------
    +++++++++++++++ ++++++++++++++
    +++++++++++++++ ++++++++++++++
    +++++++++++++++ ++++++++++++++


    Once again, When I press any key, the form gets submitted but the retrieved data does not gets listed exactly below that given text

    for more precise vision please use google chrome's omini box.
    when you press any key on keyboard, the results appera right under the search text


    and please be notified that I have to use position:absolu te; and the top:JavaScript-Given-Value property of CSS in may page

    Anybody please help me with that.

    Thank You verymuch in advance.
    Last edited by ahmednawazbutt; Apr 25 '13, 10:39 AM. Reason: Forgot to tell about to use of Abolute position and avoid Relative Position
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    read about offsetleft and offsettop.

    and try this function


    Code:
    function getPosition(obj){
        var topValue= 0,leftValue= 0;
        while(obj){
    	leftValue+= obj.offsetLeft;
    	topValue+= obj.offsetTop;
    	obj= obj.offsetParent;
        }
    	var position=new Object();
        position.x = leftValue ;
    	position.y = topValue;
        return position;
    }

    Comment

    Working...