Results 1 to 6 of 6

Thread: textarea counter

  1. #1

    Thread Starter
    Hyperactive Member Radames's Avatar
    Join Date
    Feb 2001
    Location
    Tech Tropics
    Posts
    360

    Talking textarea counter

    I want a textarea field and a counter that lets the user know how many characters he has typed in. I tried something like

    <Script Language="JavaScript">
    function adding()
    {
    texto = new String()
    texto = document.Rform.Rtext.value

    document.Rform.displayChars.value = texto.lenght
    }
    </Script>
    </head>

    <body>
    <form name="Rform">
    <textarea name="Rtext" cols=10 rows=20 onChange="adding()"></textarea>

    <BR><BR>
    <input type="text" size=5 name="displayChars">


    But it doesnt work. Any ideas people?
    Top Tip: You can make friends and impress the opposite sex at geeky cocktail parties by saying "DB" instead of database. - Karl Moore

  2. #2
    scoutt
    Guest
    Code:
    function calcCharLeft(f) {
    		clipped = false
    		maxLength = 1000
            if (f.message.value.length > maxLength) { 
    	        f.message.value = f.message.value.substring(0,maxLength)
    		    charleft = 0
    		    clipped = true
            } else {
    			charleft = maxLength - f.message.value.length
    		}
    
            f.msgCL.value = charleft
            return clipped
    }
    
    and 
    
    <input value="1000" size="3" name="msgCL" disabled>
    message is the name for the textarea you type into, but I don't think it works in NS4.x

    also I noticed you spelled length wrong in your script, change that and see if it works.

  3. #3
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    lookd correc except that your mispelled length. Is that how it is in your actual code?
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  4. #4

    Thread Starter
    Hyperactive Member Radames's Avatar
    Join Date
    Feb 2001
    Location
    Tech Tropics
    Posts
    360
    Oops!!! Looks like I meesed up good didn't I? But after I changed the typo it still wont work right. I mean, it will show the number of characters if I click on somewhere else on the page but not as I am typing them in. Is it possible to do this?
    Top Tip: You can make friends and impress the opposite sex at geeky cocktail parties by saying "DB" instead of database. - Karl Moore

  5. #5
    scoutt
    Guest
    tha tfunction I left does exactly that.

  6. #6

    Thread Starter
    Hyperactive Member Radames's Avatar
    Join Date
    Feb 2001
    Location
    Tech Tropics
    Posts
    360
    OK Thanks a lot guys. you been very helpful. Have a nice day.
    Top Tip: You can make friends and impress the opposite sex at geeky cocktail parties by saying "DB" instead of database. - Karl Moore

Posting Permissions

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



Click Here to Expand Forum to Full Width