php - Yii form textarea character limit -
i trying implement limit character showing user in textarea. code snippet seems not working. please me find error.
<?php echo $form->textarea($model, 'tr_summary', array('rows' => 2, 'cols' => 50, 'class' => 'form-control fldrequired')); ?> <div class="errormessage tour_tr_summary"></div> <script type="text/javascript"> $(".fldrequired").keyup(function(e) { fldid = $(this).attr('id'); if(fldid == 'tour_tr_summary' && $(this).val().length > 20) { $('.'+fldid).html( 'maximum 20 characters allowed'); e.preventdefault(); } }); </script>
this coding work textfield not textarea.
no javascript needed if don't care old browsers. add textarea() 1 more parameter:
array('maxlength'=>10)
not sure version of yii using, assuming code it's yii 1.x more information can find here:
http://www.w3schools.com/tags/att_textarea_maxlength.asp http://www.yiiframework.com/doc/api/1.1/cactiveform#textarea-detail
Comments
Post a Comment