textbox width

Discussion in 'Javascript' started by Alex, Feb 12, 2005.

  1. Alex

    Alex Guest

    <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?
     
    Alex, Feb 12, 2005
    #1
    1. Advertising

  2. Alex

    McKirahan Guest

    "Alex" <> wrote in message
    news:pzdPd.13496$-kc.rr.com...
    > <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?
    >
    >


    Probbaly not what you want but you can set it.

    <input type="textbox" style="width:100px" >
     
    McKirahan, Feb 12, 2005
    #2
    1. Advertising

  3. Alex

    Alex Guest

    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" <> wrote in message
    news:...
    > "Alex" <> wrote in message
    > news:pzdPd.13496$-kc.rr.com...
    >> <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?
    >>
    >>

    >
    > Probbaly not what you want but you can set it.
    >
    > <input type="textbox" style="width:100px" >
    >
    >
     
    Alex, Feb 12, 2005
    #3
  4. Alex

    RobG Guest

    Alex wrote:
    > <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?
    >
    >


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

    // IE method
    if (elem.currentStyle) {
    msg = elem.currentStyle['width'];

    // W3C method
    } else if (window.getComputedStyle) {
    var compStyle = window.getComputedStyle(elem, '');
    msg = compStyle.getPropertyValue('width');
    } 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_chap5/index5.html>



    --
    Rob
     
    RobG, Feb 12, 2005
    #4
  5. Alex

    Alex Guest

    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" <> wrote in message
    news:...
    > Alex wrote:
    >
    >> 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???

    >
    > Did you try this approach:
    >
    > d=document.getElementById(objectID);
    > alert(d.offsetHeight);
    >
    > The first 2 links show browser support:
    >
    > http://www.quirksmode.org/js/doctypes.html
    > http://www.evolt.org/article/document_body_doctype_switching_and_more/17/30655/index.html
    > http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/offsetwidth.asp
    >
    > Mike
     
    Alex, Feb 12, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. AndrewF
    Replies:
    1
    Views:
    785
    Bruce Barker
    Oct 10, 2005
  2. Xu
    Replies:
    11
    Views:
    8,570
    Andrew Thompson
    Jul 16, 2005
  3. Sean Jorden
    Replies:
    1
    Views:
    600
    laurie
    Aug 19, 2003
  4. kris
    Replies:
    11
    Views:
    876
  5. Jeff
    Replies:
    1
    Views:
    406
    Nathan Sokalski
    Oct 8, 2008
Loading...

Share This Page