Solved

text input autoresize javascript

Posted on 2008-10-29
5
267 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
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…

785 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