Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Web forms

  • 26-05-2004 05:02PM
    #1
    Closed Accounts Posts: 2,027 ✭✭✭


    Hi all

    Does anyone know of a good script that does a character count when entering text into a field on a form. Basically, I have a field on a form limited to xx characters and need the user to see how many characters they have already entered.

    All suggestions welcomed!


Comments

  • Moderators, Politics Moderators, Paid Member Posts: 44,040 Mod ✭✭✭✭Seth Brundle


    <SCRIPT LANGUAGE="JavaScript">
    <!--
    /*function textCounter(field,cntfield,maxlimit)
    {
    if (field.value.length > maxlimit) // if too long...trim it!
    field.value = message1.value.substring(0, maxlimit);
    // otherwise, update 'characters left' counter
    else
    cntfield.value = maxlimit - field.value.length;
    }
    */
    function ad_limit()
    {
    if (document.form.body.value.length > 250)//maxlimit
    document.form.body.value.substring(0,250),
    alert("There is a limit of 250 characters for per message.\nYour message contains "+ document.form.body.value.length +" characters.\nPlease refine your message.");
    else
    document.form.remLen1.value = 250 - document.form.body.value.length;
    }

    //-->
    </SCRIPT>

    <FORM NAME="form" METHOD="post" ACTION="insert_ad.asp" onSubmit="return formcheck()">
    <TEXTAREA NAME="body" COLS="50" ROWS="5" onKeyUp="return ad_limit()" onChange="return ad_limit()"></TEXTAREA>
    <INPUT readonly TYPE="text" NAME="remLen1" SIZE="3" MAXLENGTH="3" VALUE="250"> characters left
    <INPUT TYPE="SUBMIT" VALUE="Proceed" NAME="Submit">
    </FORM>


Advertisement