Hi All,
Hoping someone is able to help with this - I'm trying to do a character count where the number in a text field changes as the user types into another text field....
I have a text field ("count") which has the value of 255 then another text field ("reason") which is limited to 255 characters...
In the ("count") text field properties I have a javascript action which has this code:
getField("count").value = 255;
myString = new String (getField("reason").valueAsString);
var stringLen = myString.length // assigns length of string to variable stringLen
getField("count").value = 255 - stringLen; // a.value - stringLen;
which works fine, but the number in the ("count") text field only updates once the ("reason") text field has changed focus to another text field... is it possible to have the number in ("count") text field update "dynamically" as the user types in the ("reason") text field?
Thanks in Advance
// This is the custom Keystroke script
char_count("count");
// This is the document-level function
function char_count(f_name) {
if (!event.willCommit) {
getField(f_name).value = 255 - AFMergeChange(event).length;
}
}
Instead of hardcoding the character limit (255), you may want to set the character limit for the field and get that value in the script, making the script more generic.
e.g.,
getField(f_name).value = event.target.charLimit - AFMergeChange(event).length;
Then you might want to consider what should happen if the fields get reset or the value of "reason" is set programmatically or by importing a data file.
BTW, do not place this function in the Keystroke script.