Click here to Skip to main content
15,889,860 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all ,

I am using a jquery char counter on asp.net textbox that has the runat=server attribute.

Here is my code :

XML
<script type="text/javascript">
      var brief = document.getElementById('<%=TextBoxBriefDescription.ClientID %>');
      $(document).ready(function() {


          $(brief).jqEasyCounter({
              'maxChars': 65,
              'maxCharsWarning': 60,
              'msgFontSize': '12px',
              'msgFontColor': '#000',
              'msgFontFamily': 'Verdana',
              'msgTextAlign': 'left',
              'msgWarningColor': '#F00',
              'msgAppendMethod': 'insertBefore'
          });


      });
  </script>


but i am getting this error : Object doesn't support this property or method,which is shown on the brief variable in the javascript debugger.So how can i access the textbox in this jquery plugin ?

Thanks in advance.
Posted

1 solution

Try the code below


XML
<script src="jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="jquery.jqEasyCharCounter.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        
        var brief = document.getElementById('<%=text1.ClientID %>');
        $(document).ready(function () {
            $('#text1').jqEasyCounter({
                'maxChars': 65,
                'maxCharsWarning': 60,
                'msgFontSize': '12px',
                'msgFontColor': '#000',
                'msgFontFamily': 'Verdana',
                'msgTextAlign': 'left',
                'msgWarningColor': '#F00',
                'msgAppendMethod': 'insertBefore'
            });
        });
  </script>


following is the code for jquery.jqEasyCharCounter.min.js

JavaScript
/* jQuery jqEasyCharCounter plugin
 * Examples and documentation at: http://www.jqeasy.com/
 * Version: 1.0 (05/07/2010)
 * No license. Use it however you want. Just keep this notice included.
 * Requires: jQuery v1.3+
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */
 (function(a){a.fn.extend({jqEasyCounter:function(b){return this.each(function(){var f=a(this),e=a.extend({maxChars:100,maxCharsWarning:80,msgFontSize:"12px",msgFontColor:"#000000",msgFontFamily:"Arial",msgTextAlign:"right",msgWarningColor:"#F00",msgAppendMethod:"insertAfter"},b);if(e.maxChars<=0){return}var d=a('<div class="jqEasyCounterMsg"> </div>');var c={"font-size":e.msgFontSize,"font-family":e.msgFontFamily,color:e.msgFontColor,"text-align":e.msgTextAlign,width:f.width(),opacity:0};d.css(c);d[e.msgAppendMethod](f);f.bind("keydown keyup keypress",g).bind("focus paste",function(){setTimeout(g,10)}).bind("blur",function(){d.stop().fadeTo("fast",0);return false});function g(){var i=f.val(),h=i.length;if(h>=e.maxChars){i=i.substring(0,e.maxChars)}if(h>e.maxChars){var j=f.scrollTop();f.val(i.substring(0,e.maxChars));f.scrollTop(j)}if(h>=e.maxCharsWarning){d.css({color:e.msgWarningColor})}else{d.css({color:e.msgFontColor})}d.html("Characters: "+f.val().length+"/"+e.maxChars);d.stop().fadeTo("fast",1)}})}})})(jQuery);


The above code snippets are working for me.
 
Share this answer
 
Comments
mhamad zarif 9-Aug-11 13:15pm    
is text1 has runat=server ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900