[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How to resize a textbox on the fly.

Posted on 2004-10-25
2
Medium Priority
?
1,439 Views
Last Modified: 2008-02-26
I have an input type=text  readonly.  I want this textbox to be able to resize based on the length of the input that will populate it.  How can I do this??  I am using HTML and javascript.
0
Comment
Question by:mtiGirl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
dfu23 earned 375 total points
ID: 12403202
In a web page there is no good way to really pin down the size of text ... but you could make your best stab at it by checking the length of the value of the textbox and hopefully knowing the font family and font size you can make a decent attempt to size the textbox's width.

var txtBox = document.getElementById("myTextBox");
var length = txtBox.value.length;
txtBox.style.width = (length * 5) + "px";

try adjusting the 5 to whatever seems to work best ...
0
 
LVL 3

Expert Comment

by:nan1217
ID: 12403203
You can use this script for what you're looking for.  They have several examples to show you what it does.  The difference for you would be that the text box would be disabled and the size would default to the length of the text.

http://www.flws.com.au/showusyourcode/codeLib/code/dynamicLength.asp?catID=2
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question