Bonjour,
Je suis entrain d'intégrer dans le cadre d'un petit développement un javascript qui a pour objectif de décompter le nombre de caractères inscrit dans un champs de formulaire.
Pour un champs cela fonctionne parfaitement mais pour plusieurs j'ai des problèmes notamment dans le cadre de la gestion multilangue
A ce niveau, j'arrive bien à afficher le nbr de caractères en francais et en anglais. Mais :
Si je clique sur le champs en francais, cela décompte parfaitement
Si je clique dans le champs en anglais, ben le décompte se fait sur la partie du francais et non de l'anglais et ceux malgré la prise en compte de l'incrémentation $i
Le décompte est correct mais cela ne se fait pas en face du champs en conséquence.
Pourriez vous m'aider
Voici le script :
Code Javascript :
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='<b><span id="'+theform.toString()+'">'+thelimit+'</span></b> Max.'
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);
}
}
Voici mon code php
Code PHP :
<!-- decompte caracteres -->
<script type="text/javascript" src="includes/javascript/count_caracter/count_caracter.js"> //--></script>
<?php
for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
?>
<tr>
<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '20'); ?></td>
</tr>
<tr>
<td class="main" valign="top"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) . '  '. TEXT_PRODUCTS_PAGE_TITLE; ?></td>
<td class="main"><?php echo ' ' . tep_draw_input_field('products_head_title_tag[' . $languages[$i]['id'] . ']', (($products_head_title_tag[$languages[$i]['id']]) ? stripslashes($products_head_title_tag[$languages[$i]['id']]) : tep_get_products_head_title_tag($pInfo->products_id, $languages[$i]['id'])),'size="77", id="caracter_head_title_tag_'.$i.'"', false); ?>
<script>
displaylimit("","caracter_head_title_tag_<?php echo $i; ?>",50)
</script>
</tr>
<tr>
<td class="main" valign="top"><?php echo TEXT_PRODUCTS_HEADER_DESCRIPTION; ?></td>
<td class="main"><?php echo tep_draw_textarea_field('products_head_keywords_tag[' . $languages[$i]['id'] . ']', 'soft', '75', '5', (isset($products_head_keywords_tag[$languages[$i]['id']]) ? stripslashes($products_head_keywords_tag[$languages[$i]['id']]) : tep_get_products_head_keywords_tag($pInfo->products_id, $languages[$i]['id'])),'id="caracter_head_desc_tag_'.$i.'"'); ?>
<!-- diplay the number of caracter -->
<script>
displaylimit("","caracter_head_desc_tag_<?php echo $i; ?>",150)
</script>
</td>
</tr>
<?php
}
?>