Jump to content


Photo

input width


  • Please log in to reply
4 replies to this topic

#1 Twentyoneth

Twentyoneth
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationGlasgow, KY

Posted 19 May 2006 - 06:08 AM

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?

#2 darantes

darantes
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 19 May 2006 - 08:04 PM

Hi,

If I understood what you wish, you simply have to put an onKeyUp 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

#3 Twentyoneth

Twentyoneth
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationGlasgow, KY

Posted 19 May 2006 - 08:35 PM

Is there a way to make a max length?

#4 darantes

darantes
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 19 May 2006 - 09:21 PM

Sure, in your INPUT tag you set MAX=(any value) and the tag itself limits the character number.



#5 Twentyoneth

Twentyoneth
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationGlasgow, KY

Posted 19 May 2006 - 10:03 PM

thanks! :D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users