• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Resize TextBox automatically in struts

 
yuva rani
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Cheers.

"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
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can try javascript for events onKeypress and onBlur on text box.

<html>
<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'
onBlur='document.forms("f1").elements("Txt1").size=document.forms("f1").elements("Txt1").value.length';>

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

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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic