2

is it possible to set limit of digits or words on label?

is there any way to limit the number of digits in label in html, i've searched on internet in every possible way, but didn't get any result..please help me frnds.

like on any textbox or textarea:

<textarea maxLength="10"></textarea>

OR

<input type="text" maxLength="10" />

BTW is it possible to cut the label after certain word limit through javascript?

Krishna Sarswat
  • 117
  • 2
  • 2
  • 8

5 Answers5

4

truncate label text before display in order to limit on length.

CSS solution:
  label{
    width:20px;
    overflow: hidden;
  }

JS Solution:
  $('label:first').html().substr(0,13)
Sandip Ransing
  • 7,583
  • 4
  • 37
  • 48
2

For a label on might not need some of the following, but for a span, I needed to have the following:

span.yoyo {
  display: inline-block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow:ellipsis;
}

targetting

<span class="yoyo" title="The text here so that I can see on hovering">
  The text here so that I can see on hovering
</span>
Ustaman Sangat
  • 1,505
  • 1
  • 14
  • 26
  • 1
    I would really go for a css-only solution instead of relying on JS, because this is purely a presentation concern. Also, doing this in css allows automatic adaptation w.r.t. resizing of the element. – Ustaman Sangat Jan 19 '13 at 06:18
  • 1
    Also note I would always put title to be the entire text, so that one can see the hidden text as a "tooltip". – Ustaman Sangat Apr 24 '13 at 03:45
0

maxlength for textarea's only works in HTML5, so you'll probably need to use Javascript.

The text input should work as you wrote it.

Also - how hard did you search the Internet?

Grim...
  • 16,518
  • 7
  • 45
  • 61
0

I see, so you want to write like a short description ... Why don't you create a method which will return first 10 words or first 20 letters and then append dots?

Alexa Adrian
  • 1,778
  • 2
  • 23
  • 38
-1

The only way todo this would be to use javascript to remove any characters after a certain limit.

What you could do is set the width of the label and hide any content that overflows this width using CSS:

label{
   max-width:100px;
   overflow:hidden;
}
Jamie Dixon
  • 53,019
  • 19
  • 125
  • 162