Hemos ido viendo una series de script en php que nos servira de ayuda en nuestros proyectos.
Poco a poco iremos avanzanodo hasta llegar a crear nuestras propias aplicaciones web pero por el momento seguiresmos a paso lento pero seguro.
Este codigo ustedes lo pueden cambiar a su gusto pero sin hacer ninguna modificacion a esta linea.
onKeyUp="toCount('eBann','sBann','{CHAR} maximo caracteres',700);">
index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Contador de caracteres</title>
<script type="text/javascript" src="funciones.js"></script>
</head>
<body>
<form name="form" method="post" action="">
<textarea cols="30" rows="5" id="eBann" name="descripcion" maxlength="700" size="60" onKeyUp="toCount('eBann','sBann','{CHAR} maximo caracteres',700);">
</textarea>
<span id="sBann" class="minitext">700 caracteres maximo.</span>
</form>
</body>
</html>
funciones.js
para hacer el llamado de este archivo tendremos que utilizar esta linea antes del </head>
<script type="text/javascript" src="funciones.js"></script>
function getObject(obj) {
var theObj;
if(document.all) {
if(typeof obj=="string") {
return document.all(obj);
} else {
return obj.style;
}
}
if(document.getElementById) {
if(typeof obj=="string") {
return document.getElementById(obj);
} else {
return obj.style;
}
}
return null;
}
function toCount(entrance,exit,text,characters) {
var entranceObj=getObject(entrance);
var exitObj=getObject(exit);
var length=characters - entranceObj.value.length;
if(length <= 0) {
length=0;
text='<span class="disable"> '+text+' </span>';
entranceObj.value=entranceObj.value.substr(0,characters);
}
exitObj.innerHTML = text.replace("{CHAR}",length);
}
No hay comentarios :
Publicar un comentario