Help with character counter

  You are currently not logged in. You can view the forums, but cannot post messages. Log In | Register

31-Oct-12 09:00
Hello everyone. I wonder if anyone can help?

I found a character counter on the web and it works if used as is:

<script language="JavaScript">
function countit(what){
formcontent=what.form.charcount.value
what.form.displaycount.value=formcontent.length
}
</script>



<input type="text" name="charcount" size="40" >
<input type="button" onClick="countit(this)" value="Count" style="font-weight:bold;">
<input type="text" name="displaycount" size="3" style="font-weight:bold; text-align:center;">

[URL="http://s736.photobucket.com/albums/xx10/www_nitro-rc_co_uk/?action=view&current=1.jpg"]screenshot[/URL]

What I want to do is have the character counter on each of the 3 form input lines below instead of having it above the 3 lines (which at the moment means the customers would have to use the counter at the top and then either cut/paste or re-type the counted text into Line1, Line2 and Line 3).

I have tried doing this but (although the button does render at the side of each field) nothing works character counting wise.

To better understand, please add [URL="http://www.milenanyx.co.uk/unique-gifts/Personalised_Gifts.html"]this[/URL] test product to the cart and get to checkout page 2 to see what I mean.

I would really appreciate it if someone could get this to work. Thanks.
01-Nov-12 06:21
So! What you are asking is how to get a counter for each textbox, yes?


And why are you not simply using the maxlength attribute?

http://www.w3schools.com/tags/att_input_maxlength.asp

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/
02-Nov-12 04:24
maybe you need something like this:

<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8"/>
<script language="JavaScript">
function countit() {
var myTextFieldVal = document.getElementById('charcount').value;
document.getElementById('displaycount').value = myTextFieldVal.length;
}
</script>
</head>
<body>
<form>
<input type="text" id="charcount" size="40">
<input type="button" onClick="countit()" value="Count" style="font-weight:bold;">
<input type="text" id="displaycount" size="3" style="font-weight:bold; text-align:center;">
</form>
</body>
</html>

 
New posts
Old posts

Follow Elated