Twentyoneth Posted May 19, 2006 Share Posted May 19, 2006 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? Quote Link to comment Share on other sites More sharing options...
darantes Posted May 19, 2006 Share Posted May 19, 2006 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 luckDiogo Quote Link to comment Share on other sites More sharing options...
Twentyoneth Posted May 19, 2006 Author Share Posted May 19, 2006 Is there a way to make a max length? Quote Link to comment Share on other sites More sharing options...
darantes Posted May 19, 2006 Share Posted May 19, 2006 Sure, in your INPUT tag you set MAX=(any value) and the tag itself limits the character number. Quote Link to comment Share on other sites More sharing options...
Twentyoneth Posted May 19, 2006 Author Share Posted May 19, 2006 thanks! :D Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.