Jump to content

Textfield question


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.
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.

Edited by Fmdpa
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...