Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Web forms

Options
  • 26-05-2004 5: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 Posts: 39,939 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