textbox width

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

    #1

    textbox width

    <html>
    <body>
    <form>
    <input type="textbox" id="myTxt" value="what's my width?"
    onClick="alert( this.width)">
    </form>
    </body>
    </html>

    how can I get a handle on the width of that textbox? Or can I at all?


  • McKirahan

    #2
    Re: textbox width

    "Alex" <alexwagnerOwal laDcom@remove.t his> wrote in message
    news:PzdPd.1349 6$w75.12920@twi ster.rdc-kc.rr.com...[color=blue]
    > <html>
    > <body>
    > <form>
    > <input type="textbox" id="myTxt" value="what's my width?"
    > onClick="alert( this.width)">
    > </form>
    > </body>
    > </html>
    >
    > how can I get a handle on the width of that textbox? Or can I at all?
    >
    >[/color]

    Probbaly not what you want but you can set it.

    <input type="textbox" style="width:10 0px" >


    Comment

    • Alex

      #3
      Re: textbox width

      right, and i'm aware of that... how would you then--ever--be able to
      determine the height of an object on a page?? not even when a stylesheet
      style is set does it seem to work?!

      ANY ideas???


      "McKirahan" <News@McKirahan .com> wrote in message
      news:ke6dnR_t39 LF-pDfRVn-tQ@comcast.com. ..[color=blue]
      > "Alex" <alexwagnerOwal laDcom@remove.t his> wrote in message
      > news:PzdPd.1349 6$w75.12920@twi ster.rdc-kc.rr.com...[color=green]
      >> <html>
      >> <body>
      >> <form>
      >> <input type="textbox" id="myTxt" value="what's my width?"
      >> onClick="alert( this.width)">
      >> </form>
      >> </body>
      >> </html>
      >>
      >> how can I get a handle on the width of that textbox? Or can I at all?
      >>
      >>[/color]
      >
      > Probbaly not what you want but you can set it.
      >
      > <input type="textbox" style="width:10 0px" >
      >
      >[/color]


      Comment

      • mscir

        #4
        Re: textbox width

        Alex wrote:[color=blue]
        > <input type="textbox" id="myTxt" value="what's my width?" onClick="alert( this.width)">[/color]
        <snip>[color=blue]
        > how can I get a handle on the width of that textbox? Or can I at all?[/color]

        This works in my IE 6, Netscape 7.2, Firefox 1.0

        function showwidth(){
        t=document.getE lementById('txt 1');
        alert(t.offsetW idth);
        }

        <input type="textbox" id="txt1" value="what's my width?">

        Comment

        • mscir

          #5
          Re: textbox width

          Alex wrote:
          [color=blue]
          > right, and i'm aware of that... how would you then--ever--be able to
          > determine the height of an object on a page?? not even when a stylesheet
          > style is set does it seem to work?!
          >
          > ANY ideas???[/color]

          Did you try this approach:

          d=document.getE lementById(obje ctID);
          alert(d.offsetH eight);

          The first 2 links show browser support:


          Founded in 1998, evolt.org was one of the oldest Web development communities in existence. Through our mailing lists, articles, and archives, we have strived to work together in sharing our collective knowledge to improve the Web for all of us.

          http://msdn.microsoft.com/workshop/a...ffsetwidth.asp

          Mike

          Comment

          • RobG

            #6
            Re: textbox width

            Alex wrote:[color=blue]
            > <html>
            > <body>
            > <form>
            > <input type="textbox" id="myTxt" value="what's my width?"
            > onClick="alert( this.width)">
            > </form>
            > </body>
            > </html>
            >
            > how can I get a handle on the width of that textbox? Or can I at all?
            >
            >[/color]

            <form action="">
            <input type="textbox" id="myTxt" value="what's my width?"
            onClick="
            var msg;
            var elem = this;

            // IE method
            if (elem.currentSt yle) {
            msg = elem.currentSty le['width'];

            // W3C method
            } else if (window.getComp utedStyle) {
            var compStyle = window.getCompu tedStyle(elem, '');
            msg = compStyle.getPr opertyValue('wi dth');
            } else {
            msg = 'The methods I tried ain\'t '
            + 'supported by your browser.';
            }

            alert(msg)">
            </form>

            However, you will notice that IE very helpfully returns "auto" if
            you haven't specified a width. Firefox gives a response in px.

            Courtesty of:


            <URL:http://www.oreillynet. com/pub/a/javascript/excerpt/JSDHTMLCkbk_cha p5/index5.html>



            --
            Rob

            Comment

            • Alex

              #7
              Re: textbox width

              suh-weet!!

              Mike, that's spot-on EXACTLY what I was looking for. thanks so much! Do you
              know of a good JS reference?

              thanks again!


              "mscir" <mscir@yahoo.co m> wrote in message
              news:110quorhaq rc356@corp.supe rnews.com...[color=blue]
              > Alex wrote:
              >[color=green]
              >> right, and i'm aware of that... how would you then--ever--be able to
              >> determine the height of an object on a page?? not even when a stylesheet
              >> style is set does it seem to work?!
              >>
              >> ANY ideas???[/color]
              >
              > Did you try this approach:
              >
              > d=document.getE lementById(obje ctID);
              > alert(d.offsetH eight);
              >
              > The first 2 links show browser support:
              >
              > http://www.quirksmode.org/js/doctypes.html
              > http://www.evolt.org/article/documen...655/index.html
              > http://msdn.microsoft.com/workshop/a...ffsetwidth.asp
              >
              > Mike[/color]


              Comment

              • mscir

                #8
                Re: textbox width

                Alex wrote:[color=blue]
                > ... Do you know of a good JS reference?[/color]

                Google for "JavaScript 1.5 reference" and you'll find lots of them.






                I learned a LOT (including offsetWidth) from this newsgroup. When I run
                into problems I use Google, and search this newsgroup to see if similar
                problems have been solved here.

                Also, please don't top post, it throws off the Q&A flow.


                Good Luck,
                Mike

                Comment

                Working...