Solved

text input autoresize javascript

Posted on 2008-10-29
5
265 Views
Last Modified: 2012-05-05
I need to make an input / textbox autoresize to the width of its contents.

dim w
w = document.getElementsByName("T1").textwidth("text")
document.getElementsByName("T1").width = w

does not work.
Thanks
0
Comment
Question by:sidwelle
  • 3
  • 2
5 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 22834831
Give your input box an id="T1" as well and then try:

dim w
w = Len( document.getElementById("T1").value )
document.getElementById("T1").size = w
0
 

Author Comment

by:sidwelle
ID: 22835116
dim w
w = Len( document.getElementById("T1").value )
document.getElementById("T1").width = (w * 7) + 7

This kinda works, but not all the time.  I was looking for some auto feature.
Or an AutoSize would be cool ...
0
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 22835303

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

 "http://www.w3.org/TR/html4/loose.dtd">
 

<html>

<head>

<title></title>

<script type="text/vbscript">

Sub resizeBox

	Dim w

	w = Len( document.getElementById("T1").value ) + 1

	document.getElementById("T1").size=w

End Sub

</script>

</head>

<body>

	<input type="text" size=1 name="T1" id="T1" onkeypress="resizeBox "/>

</body>

</html>

Open in new window

0
 

Author Comment

by:sidwelle
ID: 22835585
Any way to do this automatic ?, the kerning fonts leave a little to be desired.
0
 
LVL 82

Expert Comment

by:hielo
ID: 22835766
>>Any way to do this automatic ?,
No. You will need to use scripting as shown previously
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now