Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Mr Crowley

Limitar o nº de caracters numa textarea

Recommended Posts

tenho um campo do tipo textarea

porem tenho que limitar ele a 100 caracteres

como faço isso?

e mostrar ao usuario qtos caracteres foram usados, no tempo que ele vai digitando vai fazendo a mininuição dos caracteres para ele saber o qto falta

ja vi isso em alguns sites, mais nao to encontrando nenhum agora...

quem pude me ajudar...

 

faloe e at+

tentei fazer isso mais nao funcionou....

<textarea name="Desc" cols="50" rows="2" size="100" maxlength="100" class="FORMULARIO_Campo" id="Desc"></textarea>

Compartilhar este post


Link para o post
Compartilhar em outros sites

<script language="JavaScript">  var ns6 = document.getElementById && !document.all // FUNÇÃO QUANTIDADE DE CARACTERESfunction RestringeInput(maxlength,e,placeholder){  if ( window.event && event.srcElement.value.length >= maxlength ) {  return false  } else if ( e.target && e.target == eval( placeholder ) && e.target.value.length >= maxlength ) {  var PressTecla = /[a-zA-Z0-9\.\,\/]/ //detecta caracteres alfanuméricos  if ( PressTecla.test ( String.fromCharCode ( e.which ) ) ) {       e.stopPropagation()}}}function ContaLimite( maxlength , e , placeholder ) {  var theform = eval( placeholder )  var lengthleft = maxlength-theform.value.length  var placeholderobj = document.all ? document.all[placeholder] : document.getElementById( placeholder )  if ( window.event || e.target&&e.target == eval( placeholder ) ){  if ( lengthleft < 0 )       theform.value = theform.value.substring( 0 , maxlength )       placeholderobj.innerHTML = lengthleft}}function MostraLimite( theform,thelimit ) {  var limit_text = '<span id="'+theform.toString()+'" style="font-family:Arial, Helvetica, sans-serif; font-size:11px; color:#B60807">'+thelimit+'</span><span style="font-family:Arial, Helvetica, sans-serif; font-size:11px; color:#B60807"> caracteres restantes.</span>'  if ( document.all || ns6 )  document.write( limit_text )  if ( document.all ) {           eval( theform ).onkeypress = function(){ return RestringeInput( thelimit,event,theform )}           eval( theform ).onkeyup = function(){ ContaLimite( thelimit,event,theform ) }  } else if ( ns6 ) {  document.body.addEventListener( 'keypress', function( event ) { RestringeInput( thelimit , event , theform ) }, true );  document.body.addEventListener( 'keyup', function( event ) { ContaLimite( thelimit , event , theform ) }, true );}}</script>
Abaixo do textarea você coloca

 

<script>MostraLimite(document.form.elements["nometextarea"],1025)</script>

 

1025 o limite de caracteres... você pode modificar...

 

http://forum.imasters.com.br/public/style_emoticons/default/bye1.gif

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.