File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Resize TextBox automatically in struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Barcodes with iOS this week in the iOS forum
or Core Java for the Impatient in the Java 8 forum!

JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Resize TextBox automatically in struts" Watch "Resize TextBox automatically in struts" New topic

Resize TextBox automatically in struts

yuva rani

Joined: Mar 17, 2008
Posts: 14
I'm creating a form in struts where in i need to re-size the Text Boxes automatically when i type long strings.
could you please give some suggestions to do it.
thanks in advance
Roberto Hernandez
Ranch Hand

Joined: Apr 29, 2009
Posts: 33
As far as I know, there's not an easy way to do that once the page has been rendered. What you could do if you really want to have large textboxes is to get the size of your string and then pass that number as a parameter to the JSP, that way your textbox will always be big enough for your string:
For instance:

Your number could be smaller/bigger than the text length and you can play around with it until you get it right. But I'm pretty sure you can figure that out.

"Sorry, I misunderstood your problem. You're saying you want to resize the textbox as you type the string. That's more complex. The example above only applies when you already have a string coming from the request."
yuva rani

Joined: Mar 17, 2008
Posts: 14
I can try javascript for events onKeypress and onBlur on text box.

<form name="f1">
<input type="text" name="Txt1" value="" size="10"onKeyPress='document.forms("f1").elements("Txt1").size=document.forms("f1").elements("Txt1").value.length+2'

<input type="text" name="Txt2" value="" size="10" >
<input type="button" name="btn1" Value="**enter**" onClick= "alert('hai');" >

onKeyPress, the size to increased to "String size + 2" and onBlur, the text box size sets to the String size.

I would like to know is there any other better option for resizing textBox automatically.
please suggest.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902

yuva rani wrote:I would like to know is there any other better option for resizing textBox automatically.

Its JavaScript question and not Struts specific one, so better asked the same question in JavaScript-Html forum..

And for my input: the logic is correct for resizing the text box...

[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
I agree. Here's the link:
subject: Resize TextBox automatically in struts