Forum Moderators: open
<textarea name="firstwords"
onKeyDown="textCounter(document.metas.firstwords,document.metas.remLen2)"
onKeyUp="textCounter(document.metas.firstwords,document.metas.remLen2)">
</textarea>
<input readonly type="text" name="remLen2" size="3" maxlength="3">
I have also called the function in body onload
javascript
function textCounter(field,cntfield) {
cntfield.value = field.value.length;
}
I want to somehow use the following to get
var strip = "";
strip = field.replace(/<[^>]*>/g, "");
cntfield.value = strp.length;
I am rather new to Javascript syntax. Your help would be appreciated.
function textCounter(field,cntfield) {
var strip="";
strip = field.replace(/<[^>]*>/g, "");
cntfield.value = strip.length;
}
error=object doesn't support this property or method refering to the -> cntfield.value = strip.length;
I have tried with cntfield.value = strip.value.length;
Mixing a variable, with a form field = issues
var strip="";
strip = field.replace(/<[^>]*>/g, "");
cntfield.value = strip.length.toString;
}
same error for the cntfield.value line - object doesn't support this method. Thanks for your help, but we havn't got there yet.
<form method="post" action="admin.php" name="metas">
<textarea name="firstwords" onKeyDown="textCounter(document.metas.firstwords,document.metas.remLen2)"
onKeyUp="textCounter(document.metas.firstwords,document.metas.remLen2)"></textarea>
<input readonly type="text" name="remLen2" size="3" maxlength="3">
</form>
that is: <name="remLen2" id="remLen2"> and <name="firstwords" id="firstwords">
problem:
when submitting a form the name attribute is used
when referencing form elements in a javascript the id attribute is used
thus, you need to define both an id and a name attribute for all form elements
First order of business is to find out what's getting into the script. Insert these lines as the first two in you javascript:
alert(field);
alert(cntfield);
and see if they have got the values you expect.
Another thing to try is to assign a value attribute to your remLen2 in the html code