?
Solved

How to resize a textbox on the fly.

Posted on 2004-10-25
2
Medium Priority
?
1,442 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
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month12 days, 23 hours left to enroll

579 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