Jump to content

Add counter in field


Recommended Posts

Hello,

 

I'm writing a module and i woul'd like to add a counter for characters. I tried with html it did not work.

I tried with php, was the same...

 

What i did :

        /*Variable qui contient un tableau*/
        $fields_form[1]['form'] = array(
            /*Ce tableau va gérer l'HTML de la page de configuration*/
            'legend' => array(
                'title' => $this->l('Envoie'), //Titre en entête
            ),
            'input' => array( //2e input
                array(
                    'id' => 'envoie', //id de la balise input
                    'type' => 'textarea', //Du type texte
                    'label' => $this->l('150 caractères restants'), //nom de l'input
                    'name' => 'SEND', //Signature de l'input
                    'size' => 20, //Nombre de caractères
                    'required' => true, //Champs obligatoire
                    'onkeydown' => 'return (this.value.length<=150)',
                    'onkeyup' => 'this.value=this.value.substr(0,150);envoie.innerHTML=(150-this.value.length)+' 'caractères restants'''
                )  
            ),

            'submit' => array( //Bouton Sauvegarder
                'title' => $this->l('Save'),
                'class' => 'button'
            )
        );

I'm trying to add this html code that works fine :

<html>
<style>div{color:#888888;font-family:tahoma;font-size:12}</style>
<body>
<div id="nbmax">150 caractères restants</div>
<textarea style="width:350px;height:80px" onkeydown="return (this.value.length<=150);" onkeyup="this.value=this.value.substr(0,150);nbmax.innerHTML=(150-this.value.length)+' caractères restants'">
</textarea>
</body>
</html>

Any idea ? 

 

Be cool i'm french :)

 

Thank you !

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...