Jump to content

Archived

This topic is now archived and is closed to further replies.

Twentyoneth

input width

Recommended Posts

How would you make the width of an input text field as wide as the ammount of characters inside the text field, but with a max?

Share this post


Link to post
Share on other sites
Hi,

If I understood what you wish, you simply have to put an [b]onKeyUp [/b]event in your input tag. This onkeyUp event has to call a java script function that changes the width of the input field like this:

[!--coloro:#3333FF--][span style=\"color:#3333FF\"][!--/coloro--]onKeyUp='changeWidth(this)'[!--colorc--][/span][!--/colorc--]

function changeWidth(obj)
{

obj.style.width = obj.value.length * (any constant here)

}

where obj is the input field passed as parameter into the onKeyUp event as [!--coloro:#009900--][span style=\"color:#009900\"][!--/coloro--]this[!--colorc--][/span][!--/colorc--].

the constant is any value (in pixels) that multiplies the length of the input field value to make the width of the field looks good ;)

I hope it helps, good luck
Diogo

Share this post


Link to post
Share on other sites
Sure, in your INPUT tag you set MAX=(any value) and the tag itself limits the character number.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.