SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    javascript text counter - detect code?

    I'm using a textarea character counter/limiter which is working great. However, I'm now in need of something that can detect code and NOT count that.

    Let's say I have a textarea and it will only accept 25 characters. The following sentence is 21 characters, so it will be accepted:
    Code:
    visit my website here
    Now, if I insert a link into that:
    Code:
    visit my website <a href="http://www.mywebsite.com">here</a>
    it's now 60 characters. However, the visible text in the web page is still 21 characters. But, since only 25 characters are allowed, this is what will be inserted into the database:
    Code:
    visit my website <a href="
    So, when that bit is echo'ed to the browser, it's not a pretty picture. Actually, things start to break right about then.

    This is the counter that I'm using. Is there anything that can be done about this problem?

    PHP Code:
    function limitText(limitFieldlimitCountlimitNume) {
        
    limitField.value limitField.value.substring(0limitNum);    // ensures length in case of Copy&Paste
        
    var obj document.getElementById(limitCount);
        
    obj.innerHTML limitNum limitField.value.length;
        var 
    goodkeys = new Array(89333435363738394046);
        for (
    i=0goodkeys.lengthi++) { if (e.keyCode == goodkeys[i]) return true; }    // allow delete, backspace, arrows, etc.
        
    if (limitField.value.length >= limitField.getAttribute("maxlength")) return false;    // if too many chars, just ignore key event
        
    return true;
    }

    echo 
    'onkeydown="limitText(this,\''.$name.''.'_tfcount\','.$head_limit.',event);" onkeyup="limitText(this,\''.$name.''.'_tfcount\','.$head_limit.',event);" '

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if character is equal to "<" stop counting. if character is equal to ">" start counting.

    I'm using a textarea character counter/limiter which is working great.
    Ok.
    However, I'm now in need of something that can detect code and NOT count that.
    Write a javascript to do that. Or hire a web programmer. I charge $120/hr.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •