+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14

Thread: Absolute Positioning relative to textbox

  1. #1
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Absolute Positioning relative to textbox

    I have a textbox, to which I want to link a div to show up when a key is pressed, positioned underneath the textbox.

    The code I have works fine in FF, but in IE6, the positioning is incorrect and the div appears off to the left of the screen.

    The code I have is:-
    JS
    Code:
    function autoComplete(txtbox,listholder,type)
    {
        var txt = document.getElementById(txtbox);
        var list = document.getElementById(listholder);
        if (txt.value.length <= 0) {
            list.style.display = 'none';
        } else {
            var posLeft = findPos(txt)[0];
            var posTop = findPos(txt)[1];
            //alert(posLeft + ':' + posTop);
            list.style.left = posLeft;
            list.style.top = posTop + txt.offsetHeight;
            list.style.display = '';
        }
    }
    function findPos(obj) {
        var oNode = obj;
        var curleft = obj.offsetLeft;
        var curtop = obj.offsetTop;
        if (obj.offsetParent) {
            curleft = 0;
            curtop = 0;
            while (obj = obj.offsetParent) {
                curleft += obj.offsetLeft;
                curtop += obj.offsetTop;
            }
        }
        return [curleft, curtop];
    }
    
    CSS of the div
    Code:
    .autoCompleteHolder
    {
        position:absolute;
        background-color:#B1B3FF;
        border:solid 1px #336799;
        width:200px;
        height:100px;
        z-index:100;
        overflow:auto;
    }
    
    HTML
    Code:
    <asp:TextBox ID="txtBusiness" runat="server" AutoCompleteType="Disabled" CssClass="textbox8" Width="200px" MaxLength="255" />
    <div id="txtBusinessList" class="autoCompleteHolder" style="display:none;"></div>
    
    How can I correct for IE6?

  2. #2
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Try adding a left property to that class, i.e.:
    Code:
    .autoCompleteHolder
    {
        position: absolute;
        left:  300px;
    }
    
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  3. #3
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Nope...Didn't make any difference...Also, that messed up FF...

    Could it be because I'm using display:none?

  4. #4
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Well, why are you using absolute positioning in the first place? Typically you specify top, left, right, bottom for this...
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  5. #5
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    I'm using absolute positioning because I want it to float over other objects, which as I understand it is how to achieve this in IE.

    Effectively it's an auto complete extender, but I want to be able to do pass back more information to it than the standard extender allows. I need to pass back two pieces of data so that one bit of data is passed to a hidden field when one of the items in the auto complete list is clicked and the textbox is completed with a different piece of data.

    I don't think this can be achieved with the auto complete extender. Perhaps I'll just try the auto complete extender and see how it's rendered in IE.

  6. #6
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    R, take a look at the following. I created a span with an ID of "floatover" which is also in the CSS markup in the head. Is this what you're trying to accomplish?

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    <!--
    body {
        font: 100% Verdana, Arial, Helvetica, sans-serif;
        background: #666666;
        margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */
        padding: 0;
        text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
        color: #000000;
    }
    .oneColElsCtr #container {
        width: 46em;
        background: #FFFFFF;
        margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */
        border: 1px solid #000000;
        text-align: left; /* this overrides the text-align: center on the body element. */
    }
    .oneColElsCtr #mainContent {
        padding: 0 20px; /* remember that padding is the space inside the div box and margin is the space outside the div box */
    }
    
    #floatover
    {
    display:block;
    position:absolute;
    top:5em; left:40em; width:200px;
    margin:10px;
    border:1px solid #88979E;
    background-color:#D8E0D2; color:#000;
    text-align: left
    }
    -->
    </style></head>
    
    <body class="oneColElsCtr">
    
    <div id="container">
      <div id="mainContent">
        <h1> Main Content </h1>
        <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent aliquam,  justo convallis luctus rutrum, erat nulla fermentum diam, at nonummy quam  ante ac quam. Maecenas urna purus, fermentum id, molestie in, commodo  porttitor, felis. Nam blandit quam ut lacus. Quisque ornare risus quis  ligula. Phasellus tristique purus a augue condimentum adipiscing. Aenean  sagittis. Etiam leo pede, rhoncus venenatis, tristique in, vulputate at,  odio. Donec et ipsum et sapien vehicula nonummy. Suspendisse potenti. Fusce  varius urna id quam. Sed neque mi, varius eget, tincidunt nec, suscipit id,  libero. In eget purus. Vestibulum ut nisl. Donec eu mi sed turpis feugiat  feugiat. Integer turpis arcu, pellentesque eget, cursus et, fermentum ut,  sapien. Fusce metus mi, eleifend sollicitudin, molestie id, varius et, nibh.  Donec nec libero.</p>
        <h2>H2 level heading </h2>
        <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent aliquam,  justo convallis luctus rutrum, erat nulla fermentum diam, at nonummy quam  ante ac quam. Maecenas urna purus, fermentum id, molestie in, commodo  porttitor, felis. Nam blandit quam ut lacus. Quisque ornare risus quis  ligula. Phasellus tristique purus a augue condimentum adipiscing. Aenean  sagittis. Etiam leo pede, rhoncus venenatis, tristique in, vulputate at, odio.</p>
        <span id="floatover">This box should float over the other content.Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent aliquam,  justo convallis luctus rutrum, erat nulla fermentum diam, at nonummy quam  ante ac quam. Maecenas urna purus, fermentum id, molestie in, commodo  porttitor, felis. Nam blandit quam ut lacus. Quisque ornare risus quis  ligula. Phasellus tristique purus a augue condimentum adipiscing. Aenean  sagittis. Etiam leo pede, rhoncus venenatis, tristique in, vulputate at, odio.</span>
        <!-- end #mainContent --></div>
    <!-- end #container --></div>
    </body>
    </html>
    
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  7. #7
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    The problem is really with getting it to float, it's getting it positioned correctly relative to the textbox I want it to appear underneath.

    Trying to get the left and top positions of the textbox and then place the position of the floating div directly underneath the textbox. I can't seem to get IE6 to retrieve the correct left and top values.

  8. #8
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Does this apply to you? The IE6 Absolute Positioning Bug
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  9. #9
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Quote Originally Posted by jmurrayhead View Post
    Does this apply to you? The IE6 Absolute Positioning Bug
    I saw that page and tried it, but it didn't help.

    Have found an example autocomplete with Javascript so am going to see if I can dissect it...

    Will post if I manage to find an answer..

  10. #10
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    I tried this code and the box is appearing in the middle of the browser.
    Code:
    var curleft = document.getElementsByTagName('body')[0].offsetLeft; 

    So, in order to calculate the position of the textbox, it's starting in the wrong place. I thought the body tag should be at the far left.

    Any ideas?

+ Reply to Thread
Page 1 of 2 1 2 LastLast

Similar Threads

  1. textbox events
    By todd2006 in forum .NET Development
    Replies: 12
    Last Post: April 13th, 2009, 09:16 AM
  2. CSS positioning woes...
    By bryceowen in forum HTML & CSS Help
    Replies: 9
    Last Post: February 25th, 2009, 12:18 PM
  3. validate empty textbox js
    By tulz in forum JavaScript Programming
    Replies: 1
    Last Post: February 11th, 2009, 06:13 AM
  4. textbox validation
    By todd2006 in forum JavaScript Programming
    Replies: 6
    Last Post: July 2nd, 2008, 02:30 PM
  5. Textbox or List help
    By Rebelle in forum JavaScript Programming
    Replies: 9
    Last Post: April 21st, 2008, 11:00 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO