textbox and div

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alex

    #1

    textbox and div

    could someone please point me to a site with an explanation or give me a
    *very* simple example of a div that would open right below a textbox on a
    page. I've seen lots of examples out there. Unfortunately I don't have time
    right now to dig through that code to extract the basic functionality. The
    one implementation that really hits the spot can be found here:



    look at the "Calendar Popup with Textbox and Image:"

    thank you so much in advance!!




  • mscir

    #2
    Re: textbox and div

    Alex wrote:[color=blue]
    > could someone please point me to a site with an explanation or give me a
    > *very* simple example of a div that would open right below a textbox on a
    > page. I've seen lots of examples out there. Unfortunately I don't have time
    > right now to dig through that code to extract the basic functionality. The
    > one implementation that really hits the spot can be found here:[/color]

    I like this one:



    The download has nice example code:



    Mike

    Comment

    • Alex

      #3
      Re: textbox and div

      Thanks, Mike, for the reply! The problem with the tigra implementation is
      that it pops up an actual browser window and not a div. also, I don't really
      need it for a calendar right now just to display some additional information
      about the textbox the user just clicked on... does that make sense?

      Here's a mind-numbingly simple example that I need to be converted to the
      point where the divs (when shown) will not push other content down but
      "float" right below the textbox... I guess the style has to change to
      position:absolu te... but how can I grab the coordinates to put the div in??

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
      <html>
      <head>
      <title>My cool div pop-out</title>
      </head>

      <body>
      <form>
      <table border=1>
      <tr>
      <td>some field here</td>
      <td><input type="text" id="thisText"
      onClick="JavaSc ript:document.a ll.divOne.style .display=''"><d iv id="divOne"
      style="display: none;position:r elative;border: 1px
      solid;width:200 px;height:150px "></div></td>
      </tr>
      <tr>
      <td>some field there</td>
      <td><input type="text" id="thisText"
      onClick="JavaSc ript:document.a ll.divTwo.style .display=''"><d iv id="divTwo"
      style="display: none;position:r elative;border: 1px
      solid;width:200 px;height:150px "></div></td>
      </tr>
      </table>
      </form>
      </body>
      </html>

      "mscir" <mscir@yahoo.co m> wrote in message
      news:110ock4a49 qnec5@corp.supe rnews.com...[color=blue]
      > Alex wrote:[color=green]
      >> could someone please point me to a site with an explanation or give me a
      >> *very* simple example of a div that would open right below a textbox on a
      >> page. I've seen lots of examples out there. Unfortunately I don't have
      >> time
      >> right now to dig through that code to extract the basic functionality.
      >> The
      >> one implementation that really hits the spot can be found here:[/color]
      >
      > I like this one:
      >
      > http://www.softcomplex.com/products/...dar/demo1.html
      >
      > The download has nice example code:
      >
      > http://www.softcomplex.com/products/.../download.html
      >
      > Mike[/color]


      Comment

      • mscir

        #4
        Re: textbox and div

        Alex,
        [color=blue]
        > Thanks, Mike, for the reply! The problem with the tigra implementation is
        > that it pops up an actual browser window and not a div. also, I don't really
        > need it for a calendar right now just to display some additional information
        > about the textbox the user just clicked on... does that make sense?[/color]

        Sorry I didn't read it correctly. What do you think of using hovertext?

        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">

        <html>

        <head>
        <title>Pure css tooltips by santaklauss</title>

        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">

        <meta name="generator " content="HAPedi t 3.0">

        <style type="text/css">
        body { width: 100%; text-align: left; }
        div#main {margin: 0 25%}
        p {line-height: 150%}
        a.info {
        position: relative;
        z-index:24;
        background-color:#cccccc;
        color:#000000;
        text-decoration:none ;
        }
        a.info:hover {z-index:25;backgr ound-color: #ff0}
        a.info span {display: none}
        a.info:hover span {
        display:block;
        position:absolu te;
        top:2em;
        left:2em;
        width:15em;
        border:1px solid #0cf;
        background-color:yellow;
        color:red;
        font-size: 1.1em;
        font-weight: bold;
        text-align: center
        }
        </style>
        </head>

        <body>

        <div id="main">

        <h3>Example code using your image:</h3>

        <hr>

        1939 September 2 - When Germany attacked Poland, the day was marked by
        raids of the German aviation on the city and fortress of Brzesc nad Bugiem
        (the city's name at that period), which caused human losses and damaged
        buildings in the city and in the fortress.
        <p>
        <a class="info" href="#">Move the Mouse over this Text Box
        <input type="text">
        <span>This text only appears in the popup when you move the mouse
        over the image.</span>
        </a>
        </p>
        <p>
        <a class="info" href="#">Move the Mouse over this Text Box
        <input type="text">
        <span>This text also appears ONLY when the mouse moves over the
        image.</span>
        </a>
        </p>
        </div>
        </body>
        </html>

        Comment

        • mscir

          #5
          Re: textbox and div

          Alex wrote:[color=blue]
          > Thanks, Mike, for the reply! The problem with the tigra implementation is
          > that it pops up an actual browser window and not a div. also, I don't really
          > need it for a calendar right now just to display some additional information
          > about the textbox the user just clicked on... does that make sense?[/color]

          If you are considering tooltips, these are pretty nice:

          http://www.dyn-web.com/dhtml/tooltips/

          Mike

          Comment

          • mscir

            #6
            Re: textbox and div

            Alex wrote:
            [color=blue]
            > Thanks, Mike, for the reply! The problem with the tigra implementation is
            > that it pops up an actual browser window and not a div. also, I don't really
            > need it for a calendar right now just to display some additional information
            > about the textbox the user just clicked on... does that make sense?[/color]

            Will something like this work?

            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
            "http://www.w3.org/TR/html4/strict.dtd">
            <html>
            <head>
            <title>My cool div pop-out</title>
            <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
            <style type="text/css">
            div.tooltip{
            width: 100%;
            border: 0;
            padding: 0;
            margin: 0;
            }
            table{
            border: 1px;
            padding: 0;
            }
            </style>
            <script type="text/javascript">
            var msg= new Array(2);
            msg[0]='This is the first<br>explan ation';
            msg[1]='This is the second<br>expla nation';
            function showmsg(n){
            d=document.getE lementById('too ltip');
            if (n==-1){
            d.innerHTML='';
            }else{
            d.innerHTML=msg[n];
            }
            }
            </script>
            </head>

            <body>
            <form action="#">
            <table border=1>
            <tr>
            <td>some field here</td>
            <td><input type="text" onMouseMove="sh owmsg(0)"
            onmouseout="sho wmsg(-1)"></td>
            <td rowspan="2"><di v id='tooltip'></div></td>
            </tr>
            <tr>
            <td>some field there</td>
            <td><input type="text" onMouseMove="sh owmsg(1)"
            onmouseout="sho wmsg(-1)"></td>
            </tr>
            </table>
            </form>
            </body>
            </html>

            Comment

            • Alex

              #7
              Re: textbox and div

              I actually have to put some information in html form in that div. since it
              doesn't really matter for the sake of this exercise I left it out. I guess I
              should have mentioned it... sorry.

              the closest I have come to my needs is this:
              http://www.dyn-web.com/dhtml/write-drag/img-txt.html

              here are some pieces that I still need to consider:

              1. four js include files sounds like a bit much for my needs.
              2. I have to turn the whole thing into a C#.NET control: the less js to
              maintain the better. but then again, includes are ok
              3. Dragging is a cool feature but not needed in my case. for that,
              ferant.com is ideal!
              4. I'll have to find the top-offsets for the height of the <input
              type="text">... how to do that?
              5. need to find a solution for the <select> z-index problem
              6. div needs to close automatically
              7. etc. etc. etc.

              I guess, nothing earth shattering... but hovertext certainly won't work. And
              I'm sure I'm missing a few things....

              Well... I've been playing around a bit more and this is what I've come up
              with... rather crude but you get the idea -- excuse the colors... ;)

              <CODE>
              <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
              <html>
              <head>
              <title>My cool div pop-out</title>
              <style>
              </style>
              </head>

              <body>
              <form>
              <table border=1>
              <tr>
              <td>some field here</td>
              <td><a id="aText"/><input class="txt" value="click here - dead!"
              type="text" xstyle="height: 40px"></td>
              </tr>
              <tr>
              <td>some field here</td>
              <td><a id="aText"/><input class="txt" value="tab here from prev. textbox,
              don't click! use dwn-arrow" type="text" style="width:40 0px" id="thisText"
              onKeyUp="tryKey (this, divOne)" onClick="openit (this, divOne)"><div
              onClick="closei t(this)" id="divOne"
              style="backgrou nd-color:#ffcc33;d isplay:none;pos ition:relative; border:1px
              solid;width:200 px;height:150px ;overflow:auto" >click on me to close... or hit
              [Esc]<br><br><br><br ><br><br><br><b r><br><br><br>< br><br><br><br> <br><br><br><br ><br><br><br><b r><br><br><br>< br><br></div></td>
              </tr>
              <tr>
              <td>some field there</td>
              <td><input type="text" id="thisText" value="click here to open"
              onClick="openit (this, divTwo)"><div onClick="closei t(this)" id="divTwo"
              style="backgrou nd-color:#ffcc33;d isplay:none;pos ition:relative; border:1px
              solid;width:200 px;height:150px ">click on me to close</div></td>
              </tr>
              <tr>
              <td>some field there</td>
              <td><select name="bother">< option>one<opti on>two<option>t hree</select></td>
              </tr>
              </table>
              </form>
              </body>
              </html>
              <script language="JavaS cript">
              function tryKey(t, d){
              var e = event.keyCode;
              //alert(typeof(e) + ': ' + e);
              if(e == 40){
              openit(t, d);
              }
              else if(e == 27){
              closeit(d);
              }
              }

              function openit(t, d){

              var x = findX(t);
              var y = findY(t);

              d.style.display =''
              d.style.positio n='absolute';
              d.style.top = y+20; //<<< needs to be determined programmaticall y!
              d.style.left = x;

              t.focus();

              }

              function closeit(o){
              o.style.display ='none';
              }

              function findX(obj)
              {
              var curleft = 0;
              if (obj.offsetPare nt)
              {
              while (obj.offsetPare nt)
              {
              curleft += obj.offsetLeft;
              obj = obj.offsetParen t;
              }
              }
              else if (obj.x) {
              curleft += obj.x;
              }
              return curleft;
              }
              function findY(obj)
              {
              var curtop = 0;
              if (obj.offsetPare nt)
              {
              while (obj.offsetPare nt)
              {
              curtop += obj.offsetTop;
              obj = obj.offsetParen t;
              }
              }
              else if (obj.y)
              curtop += obj.y;
              return curtop;
              }
              </script>


              </CODE>


              Comment

              • mscir

                #8
                Re: textbox and div

                <snip>

                How about an absolutely positioned div? You can track the mouse and make
                it appear next to the mouse, or use a simpler approach: hard code it as
                I did here. Lots less javascript with this approach: A div appears with
                the correct message, then disappears after 2 seconds.

                <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
                "http://www.w3.org/TR/html4/strict.dtd">

                <html>
                <head>
                <title>Div Tooltips</title>
                <script type="text/javascript">
                var msg=new Array(5);
                msg[1]='This is the first message to appear in the message div';
                msg[2]='This is the second message to appear in the message div';
                msg[3]='This is the third message to appear in the message div';
                msg[4]='This is the fourth message to appear in the message div';
                msg[5]='This is the fifth message to appear in the message div';
                function init(){
                msgdiv=document .getElementById ('messagediv');
                }
                function showdiv(theId) {
                hidemsgdiv();
                msgdiv.innerHTM L=msg[theId];
                msgdiv.style.vi sibility = "visible";
                // set timeout to hide div in 2 seconds
                var tid = setTimeout("hid emsgdiv()", 2000);
                }
                function hidemsgdiv() {
                msgdiv.style.vi sibility = "hidden";
                }
                </script>
                <style type="text/css">
                ..text{
                font-size: 90%;
                }
                ..hidden{
                visibility: hidden;
                border: 1px solid green;
                color: red;
                background-color: #FFFFFF;
                padding: 1px;
                position: absolute;
                width: 200px;
                height: 200px;
                top: 10px;
                left: 260px;
                }
                </style>
                </head>

                <body onload='init()' >
                <p>
                Text1 Div1&nbsp;<inpu t type="text" onMouseOver="sh owdiv(1)"><br>
                Text2 Div2&nbsp;<inpu t type="text" onMouseOver="sh owdiv(2)"><br>
                Text3 Div3&nbsp;<inpu t type="text" onMouseOver="sh owdiv(3)"><br>
                Text4 Div4&nbsp;<inpu t type="text" onMouseOver="sh owdiv(4)"><br>
                Text5 Div5&nbsp;<inpu t type="text" onMouseOver="sh owdiv(5)"><br>
                </p>
                <div class='hidden' id='messagediv' ></div>
                </body>
                </html>

                Comment

                • Alex

                  #9
                  Re: textbox and div

                  Those are two great examples. The fact that they are very concise is awsome!
                  The only *one* problem now remains that they will have to stay open as long
                  as focus is in the textbox OR they are doing something in the div -- like
                  selecting a value to be put in the textbox. Once they tab off the field,
                  click somewhere in the body of the page or just onMouseOut off the div the
                  div should "close". Thanks so much!!

                  "mscir" <mscir@yahoo.co m> wrote in message
                  news:110ojbvnvh 1cvc6@corp.supe rnews.com...[color=blue]
                  > Alex wrote:
                  >[color=green]
                  >> Thanks, Mike, for the reply! The problem with the tigra implementation is
                  >> that it pops up an actual browser window and not a div. also, I don't
                  >> really need it for a calendar right now just to display some additional
                  >> information about the textbox the user just clicked on... does that make
                  >> sense?[/color]
                  >
                  > Will something like this work?
                  >
                  > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
                  > "http://www.w3.org/TR/html4/strict.dtd">
                  > <html>
                  > <head>
                  > <title>My cool div pop-out</title>
                  > <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
                  > <style type="text/css">
                  > div.tooltip{
                  > width: 100%;
                  > border: 0;
                  > padding: 0;
                  > margin: 0;
                  > }
                  > table{
                  > border: 1px;
                  > padding: 0;
                  > }
                  > </style>
                  > <script type="text/javascript">
                  > var msg= new Array(2);
                  > msg[0]='This is the first<br>explan ation';
                  > msg[1]='This is the second<br>expla nation';
                  > function showmsg(n){
                  > d=document.getE lementById('too ltip');
                  > if (n==-1){
                  > d.innerHTML='';
                  > }else{
                  > d.innerHTML=msg[n];
                  > }
                  > }
                  > </script>
                  > </head>
                  >
                  > <body>
                  > <form action="#">
                  > <table border=1>
                  > <tr>
                  > <td>some field here</td>
                  > <td><input type="text" onMouseMove="sh owmsg(0)"
                  > onmouseout="sho wmsg(-1)"></td>
                  > <td rowspan="2"><di v id='tooltip'></div></td>
                  > </tr>
                  > <tr>
                  > <td>some field there</td>
                  > <td><input type="text" onMouseMove="sh owmsg(1)"
                  > onmouseout="sho wmsg(-1)"></td>
                  > </tr>
                  > </table>
                  > </form>
                  > </body>
                  > </html>[/color]


                  Comment

                  • Robert

                    #10
                    Re: textbox and div

                    In article <110oor1ic4080c 8@corp.supernew s.com>,
                    mscir <mscir@yahoo.co m> wrote:
                    [color=blue]
                    > var msg=new Array(5);
                    > msg[1]='This is the first message to appear in the message div';
                    > msg[2]='This is the second message to appear in the message div';
                    > msg[3]='This is the third message to appear in the message div';
                    > msg[4]='This is the fourth message to appear in the message div';
                    > msg[5]='This is the fifth message to appear in the message div';[/color]

                    A minor point or two.

                    Javascript arrays are zero based so new Array(5) says you will be using
                    array elements 0, 1, 2 3, and 4. Declaring how many elements you will
                    use is somewhat redundant because Javascript sizes the array dynamically.

                    I like to declare arrays as such:

                    var msg= [ ];

                    Although in this instance, I like the direct assignment
                    of the array values, you could also do this:

                    var msg= [
                    /* 0 */ '',
                    /* 1 */ 'This is the first message to appear in the message div',
                    /* 2 */ 'This is the second message to appear in the message div',
                    /* 3 */ 'This is the third message to appear in the message div',
                    /* 4 */ 'This is the fourth message to appear in the message div',
                    /* 5 */ 'This is the fifth message to appear in the message div'
                    ]

                    I thought the program was will written. I hope you find this suggestion
                    useful.

                    Robert

                    Comment

                    • McKirahan

                      #11
                      Re: textbox and div

                      "Alex" <alexwagnerOwal laDcom@remove.t his> wrote in message
                      news:0R2Pd.1204 5$w75.5558@twis ter.rdc-kc.rr.com...[color=blue]
                      > Those are two great examples. The fact that they are very concise is[/color]
                      awsome![color=blue]
                      > The only *one* problem now remains that they will have to stay open as[/color]
                      long[color=blue]
                      > as focus is in the textbox OR they are doing something in the div -- like
                      > selecting a value to be put in the textbox. Once they tab off the field,
                      > click somewhere in the body of the page or just onMouseOut off the div the
                      > div should "close". Thanks so much!![/color]


                      Here's a variation of mscir's that does what you want.

                      The "tooltip" is on the sameline as the text box.

                      <html>
                      <head>
                      <title>My cool div pop-out</title>
                      <style type="text/css">
                      div.tooltip {
                      width: 100%;
                      border: 0;
                      padding: 0;
                      margin: 0;
                      }
                      table {
                      border: 1px;
                      padding: 0;
                      }
                      </style>
                      <script type="text/javascript">
                      var msg = new Array();
                      msg[1] = "This is the 1st explanation";
                      msg[2] = "This is the 2nd explanation";
                      function showmsg(n) {
                      var i = Math.abs(n);
                      var d = document.getEle mentById('toolt ip'+i);
                      if (n < 0) {
                      d.innerHTML = "";
                      } else {
                      d.innerHTML = msg[n];
                      }
                      }
                      </script>
                      </head>
                      <body>
                      <form action="#">
                      <table>
                      <tr>
                      <td>some field here</td>
                      <td><input type="text" onfocus="showms g(1)" onblur="showmsg (-1)"></td>
                      <td><div id='tooltip1'></div></td>
                      </tr>
                      <tr>
                      <td>some field there</td>
                      <td><input type="text" onfocus="showms g(2)" onblur="showmsg (-2)"></td>
                      <td><div id='tooltip2'></div></td>
                      </tr>
                      </table>
                      </form>
                      </body>
                      </html>


                      Comment

                      Working...