Click to See Complete Forum and Search --> : resizeable input
zimba
01-14-2003, 10:09 AM
Hi all, I'm new to this forum (since 2 seconds)
I was looking on internet for a solution but didn't find it.
I'd like to make resizeable inputs for style.
I'd like the input textbox to resize with the lenght of the content.
like if you enter "n":
/---/
| n |
/---/
and "name" :
/--------/
| name |
/--------/
I've tried to use input_text_name.value.lenght but it doesn't support this.
How could I do this ?
Cheers
gil davis
01-14-2003, 10:24 AM
This works on IE 5.5:
<form>
<input type="text" size=1 onkeypress="this.size=this.value.length">
</form>
It does not respond to backspace, and will not grow until the third character is entered.
khalidali63
01-14-2003, 11:17 AM
the code below will work with both NS6+ and IE
cheers
Khalid
<form name="form1">
<input type="Text" name="txtF1" style="width:10pt;" onkeypress="resize(this);"></input>
</form>
<script language="JavaScript1.2">
function resize(obj){
var len = parseInt(obj.value.length);
obj.style.width=20+(len*5)+"pt";
}
</script>
zimba
01-14-2003, 12:10 PM
thx both for your responses !
I'll surely be back for more questions :P
Charles
01-14-2003, 12:31 PM
Just keep in mind that this will not work for a lot of users, which is no big loss unless you set the initial size of the text field to 1. You can re-set it to 1 using JavaScript, just don't leave JavaScript free users with a really narrow field.
zimba
01-14-2003, 02:52 PM
actually I'm developping an internat webapp for my enterprise under php, so it's ok
I know javascript is a lot of mess this is why I never wanted to use it but now I'm forced to :P
-> this is why I surely will ask some other questions.. lol
thanks