Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-26-2004, 05:11 AM   PM User | #1
lipak
New Coder

 
Join Date: Jun 2004
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
lipak is an unknown quantity at this point
Add the characters in the fields

Here is the character count script I am working with:
http://codeline-alley.digiserv.net/j...cter_count.php

I don't know how to use it so that the character count for multiple fields (text areas) is totaled and displayed in the "characters left" field.

Any help would be greatly appreciated.
lipak is offline   Reply With Quote
Old 06-26-2004, 05:25 PM   PM User | #2
Willy Duitt
Banned

 
Join Date: Sep 2003
Posts: 3,620
Thanks: 0
Thanked 0 Times in 0 Posts
Willy Duitt is an unknown quantity at this point
Is this the page you are applying the code too?

If so, I just checked at it appears to be working.
At least for two fields anyway....

.....Willy
Willy Duitt is offline   Reply With Quote
Old 06-26-2004, 06:20 PM   PM User | #3
lipak
New Coder

 
Join Date: Jun 2004
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
lipak is an unknown quantity at this point
Thanks for the reply. I found cross browser compatible code on this forum so I thought I would repost. That page you linked to is a page that does what I want to do, but it is not my page. I'm where I was before - minus the cross browser issue.
lipak is offline   Reply With Quote
Old 06-26-2004, 06:48 PM   PM User | #4
neofibril
Regular Coder

 
Join Date: Jun 2004
Location: underground
Posts: 186
Thanks: 0
Thanked 0 Times in 0 Posts
neofibril is an unknown quantity at this point
Well, I don't know what's going on with the replies above, but in response to the original question, this might work:
Code:
<body>
<script type="text/javascript">
function doCount(elem, count, limit, names)
 {
   names = names.split("+");
   var pForm = elem.form,
       total = 0,
         val = elem.value,
          ln = names.length,
           i = -1; 
   while(++i < ln)
     total += pForm[names[i]].value.length;
   total > limit ? elem.value = val.substr(0, val.length - 1) : count.value = limit - total;
 }
</script>
<form>
<fieldset style="text-align:center;padding-bottom:1em">
<legend>
<label>characters remaining: </label>
<input name="counter" value="20" size="4" readonly>
</legend>
<textarea name="txt1" cols="20" rows="2" 
onkeydown="doCount(this, counter, 20, 'txt1+txt2+txt3')" onkeyup="doCount(this, counter, 20, 'txt1+txt2+txt3')"></textarea>
<textarea name="txt2" cols="20" rows="2" 
onkeydown="doCount(this, counter, 20, 'txt1+txt2+txt3')" onkeyup="doCount(this, counter, 20, 'txt1+txt2+txt3')"></textarea>
<textarea name="txt3" cols="20" rows="2" 
onkeydown="doCount(this, counter, 20, 'txt1+txt2+txt3')" onkeyup="doCount(this, counter, 20, 'txt1+txt2+txt3')"></textarea>
</fieldset>
</form>
</body>
Edit:
I hadn't tested that in Opera: a browser that requires an additional onkeypress handler...
it also added my linebreaks to the textarea values (those have been removed).

I suppose all of the parameters should be put into the function as variables, given the number of event handlers that they'd be stuffed into.

Last edited by neofibril; 06-26-2004 at 08:33 PM..
neofibril is offline   Reply With Quote
Old 06-27-2004, 07:50 PM   PM User | #5
lipak
New Coder

 
Join Date: Jun 2004
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
lipak is an unknown quantity at this point
Smile

Sorry for the delayed reply. It works perfectly! Thank you very much neofibril and Willy Duitt for all your help. It is greatly appreciated.
lipak is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:39 AM.


Advertisement
Log in to turn off these ads.