Freelancers Network
 
skill list top cap
Homepage
Join the Freelancer's Network
Update your details
Find a freelancer
Post a project
Find a project
Projects Archive
Post a job
Find a job
Jobs Archive
See Dan's Pages
See Andy's Pages
Link to this site
Resources
Join/Leave Forum
Forum Messages
+Additions+ Adverts
Advertising
Contact Us
Subscribe to our newsletter - enter your email address and hit return
Freelancers.net is owned and operated by Andy Stowell and Dan Winchester
skill list end cap
guru web hostcom

Find me again on Freelancers.net

Re: FN-FORUM: Javascript error

date posted 21st September 2007 12:57

Here is some code I've used in the past, it works off a timer rather
than keypresses:

var maxChars = 200;
var canCount = false;
var counterTimer = null;

function countChars()
{
if (counterTimer) clearTimeout(counterTimer);

var numberOfChars = document.theForm.theTextArea.value.length;
document.getElementById("theCounter").innerHTML = "Chars left: " +
(maxChars - numberOfChars)

if ((maxChars - numberOfChars ) < 0)
{
// this could be changed to
//document.theForm.theTextArea.value =
document.theForm.theTextArea.value.substring(0, maxChars);
document.getElementById("theCounter").innerHTML = "You have entered
too much text, please reduce it";
}

if (canCount)
{
counterTimer = setTimeout("countChars()", 250);
}
}

then the textarea:





and to display the counter



Martin

On 21/09/2007 13:18, ADH WebCreations wrote:
> Hi,
>
> I'm not getting any error messages with this but it's not working
> either...!
>
> Any ideas?
>
> Thanks
> Ashley
>
> -----Original Message-----
> From: [EMAIL REMOVED] [EMAIL REMOVED] On Behalf Of Dai
> Williams
> Sent: 21 September 2007 13:09
> To: FN-FORUM / [EMAIL REMOVED]
> Subject: RE: FN-FORUM: Javascript error
>
>
> ADH WebCreations wrote:
>> and on the textbox I have:
>>
>> > onclick="javascript:calcCharLeft(this);"
>> onkeyup="javascript:calcCharLeft(this);"
>> onchange="javascript:calcCharLeft(this);">
>> Left > />
>>
>> if (document.queryform.Summary.value.length > maxLength) { is null or
>> not an object"
>
> Since you are passing the object reference into the function it is much
> cleaner, safer and more extensible to refer to it using that object
> reference e.g.
>
> function calcCharLeft(obj) {
> clipped = false;
> maxLength = 1000;
> if (obj.value.length > maxLength) {
> obj.value = obj.value.substring(0,maxLength);
> charleft = 0;
> clipped = true;
> } else {
> charleft = maxLength - obj.value.length;
> }
> prevsec++;
> if(autoprev && prevsec > 5 && prevtxt != obj.value) {
> autoPreview();
> prevtxt = obj.value;
> }
> }
>
> Can't comment whether that is the only issue, but it is certainly worth
> a
> try. Also a good idea to get in the habit of terminating statements
> with ;
> even when it is not an absolute requirement.
>
> HTH,
>
> Dai
>
>



Messages by Day
September 30th 2007
September 29th 2007
September 28th 2007
September 27th 2007
September 26th 2007
September 25th 2007
September 24th 2007
September 23rd 2007
September 22nd 2007
September 21st 2007
September 20th 2007
September 19th 2007
September 18th 2007
September 17th 2007
September 16th 2007
September 15th 2007
September 14th 2007
September 13th 2007
September 12th 2007
September 11th 2007
September 10th 2007
September 9th 2007
September 8th 2007
September 7th 2007
September 6th 2007
September 5th 2007
September 4th 2007
September 3rd 2007
September 2nd 2007
September 1st 2007


Messages by Month
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007


Messages by Year
2008
2007
2006
2005
2004
2003
2002
2001
2000