• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Resize TextBox automatically in struts

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic