cs_Manuela90
Messages postés1Date d'inscriptionmardi 23 novembre 2010StatutMembreDernière intervention23 novembre 2010
-
23 nov. 2010 à 01:23
PetoleTeam
Messages postés3426Date d'inscriptionlundi 26 décembre 2005StatutMembreDernière intervention14 janvier 2011
-
23 nov. 2010 à 18:55
Bonsoir,
Je suis très nulle en Javascript donc j'ai trouvé sur internet un compteur de caractères pour un textarea. Le problème c'est qu'il n'est pas compatible IE, le navigateur me retourne l'erreur suivante : 'document.getElementById(...)' a la valeur Null ou n'est pas un objet.
Comment faire vu que je suis très nulle
var ns6=document.getElementById&&!document.all
function restrictinput(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 pressedkey=/[a-zA-Z0-9\.\,\/]/
if (pressedkey.test(String.fromCharCode(e.which)))
e.stopPropagation()
}
}
function countlimit(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 displaylimit(thename, theid, thelimit){
var theform=theid!=""? document.getElementById(theid) : thename
var limit_text='
'+thelimit+'
'
if (document.all||ns6)
document.write(limit_text)
if (document.all){
eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
}
else if (ns6){
document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true);
document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true);
}
}
PetoleTeam
Messages postés3426Date d'inscriptionlundi 26 décembre 2005StatutMembreDernière intervention14 janvier 201117 23 nov. 2010 à 18:55
Bonjour,
l'erreur suivante : 'document.getElementById(...)' a la valeur Null la méthode document.getElementById cherche dans le document un élément ayant comme ID le paramètre entre parenthèse, si elle ne le trouve pas BOUM !!
Avec IExplorer si il n'y a pas d'ID mais un NAME cela fonctionne, pas avec les autres navigateurs.
Comment faire vu que je suis très nulle apprendre et lire des doc, mais courage RIEN c'est rien mais 2 fois RIEN c'est déjà quelque chose
pour finir il me semblait qu'avec
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>...</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
//-------------------
function nbCar( obj_){
document.getElementById('D_NB').innerHTML += ( obj_.value.length +' - ');
obj_.focus();
}
</script>
</head>
<textarea onkeyup = "nbCar(this);"></textarea>
</html>
c'était suffisant, mais je n'ai pas trop regardé le code pour savoir ce qu'il fait réellement.
;O)