0

So i have this page: http://www.prxa.info/index.php?module=articles&view=Submit

Using jquery and code i am trying found here: https://stackoverflow.com/a/13516186/1741251

I am trying to do a twitter like character count for the first textarea counting down from 255 but it doesn't seem to work for me?

I have basically no experience with javascript :(

This is the code I am using to count it:

<script type="text/javascript">
$(document).ready(function () {
    $('#tagline').keypress(function (event) {
        var max = 255;
        var len = $(this).val().length;
        if (event.which < 0x20) {
            // e.which < 0x20, then it's not a printable character
            // e.which === 0 - Not a character
            return;     // Do nothing
        }
        if (len >= max) {
            event.preventDefault();           
        }            

    });
    $('#tagline').keyup(function (event) {
        var max = 250;
        var len = $(this).val().length;       
        var char = max - len;
        $('#textleft').text(char + ' characters left');

     });

Community
  • 1
  • 1
NaughtySquid
  • 1,947
  • 3
  • 29
  • 44
  • What have you tried so far. You will need to use javascript to detect the value of the input box - on a keyUp. Then do a character count from there and alter a holder div for the number –  Dec 03 '12 at 11:46
  • Added the code i am using atm. – NaughtySquid Dec 03 '12 at 11:47
  • It's advisable to use keydown rather than keypress. Keydown is fired when the key is actually depressed. Keypress is generally fired when the key is pressed and then released, and is not an officially documented event. – AmericanUmlaut Dec 03 '12 at 11:49

1 Answers1

0

Something like this

$('#inputBox').keyup(function (event) {
    var len = $(this).val().length;
    $('#holder').text(len );
});
  • ^ start testing with a simpler code - then add complexity to add further functionality. –  Dec 03 '12 at 11:48