Maybe it is because I am way too tired as been working non-stop for days
But for whatever reason I cannot find out why all of a sudden the JS code on a part of a form is not working.
The code is supposed to count the number of Characters in a textarea field and not allow the user to type
more than the allotted number of Characters. The JS code is:
function textCounter_rem(maxlimit) {
var field = document.getElementById("description");
var cntfield = document.getElementById("rem");
if (field.value.length > maxlimit) {
field.value = field.value.substring(0, maxlimit);}
else
{cntfield.value = maxlimit - field.value.length;}
}
But all of a sudden it is not working!
You can see a sample client page here:
As you can see when you type in the field for: Description of this Site
The āNumber of Characters remainingā field is not changing and the user can type past 200!
Remember that JS can be turned off, too, so you might want to set a maxlength=ā200ā attribute in the HTML itself, or set a limit in the PHP behind the scenes.
Sorry for providing a URL that was password protected.
Here is the problem in a non-password protected mode:
So again the problem is the counter on the āDescription of this Siteā textarea is all of a sudden not working.
That is not counting as users type in and thus stopping them when they hit the maximum allowed 200 Chars!
I donāt know enough JS to help with this, so weāll have to wait for someone to step in. However, just looking at the code, I would expect field.value.length to evaluate to 3, rather than 200āif I understand .length properly. That may be a problem.
So opening the debugger (which all browsers except Firrefox have built in) and it shows that field = null.
Given that field was assigned the value document.getElementById(ādescā) a couple of lines earlier this means that there is no id=ādescā in the page - which there isnāt as the field you are trying to validate has id=ādescriptionā.