Jump to content

Textfield question


FrustratedStudent

Recommended Posts

I have seen textfield boxes on forms that have a scrollbar on the side and are seemingly limitless on the number of rows it will allow. How is that done? I know how to limit the number of rows or columns, but that is leaving me with a huge ugly textbox when I would really like to have a nice small one...If I don't make any specifications I end up with a odd small box that won't work for what I want. Suggestions?

Link to comment
Share on other sites

To my knowledge, a textarea doesn't have a limit on the amount of text allowed in it. If the rows don't fit in the area of the box a scrollbar will be added.

Link to comment
Share on other sites

To my knowledge, a textarea doesn't have a limit on the amount of text allowed in it.
HTML5 will change that: http://www.w3schools.com/html5/tag_textarea.aspCurrently, you could do the same thing with JS though (untested):
<textarea rows="5" cols="30" id="ta"></textarea><script>ta = document.getElementById('ta');max_characters = 250;ta.onkeypress = function(evt) {   evt = evt ? evt : window.event;   if (evt.keyCode) code = evt.keyCode;   else if (evt.which) code = evt.which;   else return false;   // if the textarea is at its maximum length limit then only allow the delete, enter and backspace keys (In other words, nothing can be added);   if ((code != 8 && code != 13 && code != 46) && ta.value.length > max_characters) { 	  return false; // prevent the default action (printing the character);   }}</script>

This can be bypassed by disabling Javascript, so it is purely an enhancement for the majority of users.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...