SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    I'm not a human
    Join Date
    Aug 2006
    Location
    India
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Textarea width is changing dynamically!

    hi

    i'm using a textarea in which i set the property cols=20 and i've set a default text in the textarea.

    And using javascript i'm changing the font of the text inside the textarea when i'm selecting font from a select element.

    The problem is even though i set the property cols=20 , the width of the text area is changing according to the font selected. What's the problem? I think the cols property is setting width based on the font and font size..

    But i want the text area size to be fixed. Pls help me thru
    Regards,
    Vijay
    Follow me on twitter @vijaycbe
    World Holiday Calander || My Cricket Blog

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what I thinks happening is the cols property uses EM's. As an EM is the size of an M in the current font, if you change the font, the EM size increases, thus increasing the size of the textarea.

    Probably best off setting a width value in css.


  3. #3
    SitePoint Zealot the DtTvB's Avatar
    Join Date
    Jul 2006
    Location
    Thailand
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The `cols` and `rows` attribute will set the textarea sized based on the size of the font. So if you want to size textarea and don't want its size to change, try this:

    Code:
    <textarea blah blah blah blah style="width: 300px;">

  4. #4
    SitePoint Addict CommanderZ's Avatar
    Join Date
    Apr 2006
    Location
    Czech Republic
    Posts
    236
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code JavaScript:
    document.getElementById("yourtextareaid").style.width="400px";

  5. #5
    I'm not a human
    Join Date
    Aug 2006
    Location
    India
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks all that worked nicely
    Regards,
    Vijay
    Follow me on twitter @vijaycbe
    World Holiday Calander || My Cricket Blog


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
  •