Solved

text input autoresize javascript

Posted on 2008-10-29
5
270 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
[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
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

710 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