Counter of char available on TextBox

thread: 8 messages  |  last: a year ago  |  started: friday, april 2, 2010, 2:12 pm pdt


#1  |  Mattia Bagiella (Switzerland) Switzerland
Friday, April 2, 2010, 2:12 PM PDT

Hello,

I'm asking if exist a counter of char in textbox like your textbox is limited, maxlength 250. when you are tipping char it decrease

a
char available 249

b
char available 248

Someone knows how to make this function ?

Thank you

#2  |  VexedPanda (Calgary, AB) Canada
Tuesday, April 6, 2010, 8:02 AM PDT

That should be pretty simple javascript. Look at http://www.reindel.com/five_javascript_tricks_jquery/ for an example using jQuery.

#3  |  Mattia Bagiella (Switzerland) Switzerland
Tuesday, April 6, 2010, 8:53 AM PDT

Thank you :)

Nice:


    /*
        2.) Characters Remaining Countdown
    */

    var countdown = {
        init: function() {
            countdown.remaining = countdown.max - $(countdown.obj).val().length;
            if (countdown.remaining > countdown.max) {
                $(countdown.obj).val($(countdown.obj).val().substring(0,countdown.max));
            }
            $(countdown.obj).siblings(".remaining").html(countdown.remaining + " characters remaining.");
        },
        max: null,
        remaining: null,
        obj: null
    };

.bc
#4  |  Mattia Bagiella (Switzerland) Switzerland
Tuesday, April 6, 2010, 10:00 AM PDT

Wow now I have a little problem how I can manage this code with Qcodo/PHP

QJavaScript(?) ;

:(

#5  |  Mattia Bagiella (Switzerland) Switzerland
Tuesday, April 6, 2010, 10:30 AM PDT

I make my own :) like this :


<?php  

protected function txtMotif_Create() {    
      
$this->txtMotif = new QTextBox($this);
      
$this->txtMotif->TextMode QTextMode::MultiLine;
      
$this->txtMotif->Name QApplication::Translate('Motif de suppression');
      
$this->txtMotif->Text $this->objSuppression->Motif;
      
$this->txtMotif->Required true;
      
$this->txtMotif->Rows 10;
      
$this->txtMotif->Columns 70;
      
$this->txtMotif->CssClass 'element_right';
      
$this->txtMotif->MaxLength $this->motifMaxLength;
      
$this->txtMotif->AddAction(new QKeyUpEvent(), new QAjaxAction('Count_char'));
}

protected function 
Count_char($strFormId$strControlId$strParameter) {
                    
    
$restant $this->txtMotif->MaxLength strlen($this->txtMotif->                
    
$this->lblCount->Text $restant."/".$this->txtMotif->MaxLength;
}

?>

It's good or do find any bugs ?

EDIT: nooooooo à è é count twice :(

That's no good

Any function in qcodo that count txt ? txt->Length didn't work :(

#6  |  Mattia Bagiella (Switzerland) Switzerland
Tuesday, April 6, 2010, 10:34 AM PDT

Eh eh find my solution :P

strlen(utf8_decode($this->txtMotif->Text));

Snif still not working with the char ' :'(

#7  |  Mattia Bagiella (Switzerland) Switzerland
Tuesday, April 6, 2010, 11:20 AM PDT

I found my probleme qcodo when I type ' or " add / so ' or " = 2 char :DD

#8  |  VexedPanda (Calgary, AB) Canada
Tuesday, April 6, 2010, 12:14 PM PDT

Note that this also causes all the work to be done by the server, and will cause a fair bit of network traffic, since every keystroke is causing the entire form to be submitted to the server. And the user may notice a lag due to the processing time.

You should be able to run the javascript init code in the control's _Create function by using QApplication::Execute($strJavascript);



Copyright © 2005 - 2012, Quasidea Development, LLC
This open-source framework for PHP is released under the terms of The MIT License.