I asked a similar question a couple of weeks ago, but need some more help.
I am working on a form that eventually populates a fillable PDF. I have some comment boxes set as multi-line fields, but I need to ensure that whatever comments are written on the form will fit within the space allocated in the PDF. I was going to just use maximum chars, but then realized that if a user puts carriage returns in the form it could cause those comments to exceed to space of the PDF and get cut off. So I am trying to get code to work to limit both the number of lines and the number of characters in each line.
I found this thread that looks helpful, but I have been unable to get the code to work in Forms. https://stackoverflow.com/questions/14259580/textarea-with-limited-lines-and-char-limits
There is discussion there about issues with the curser jumping around using the orignal answer, and Boris supposedly solved it with this code
var textarea = document.getElementById("splitLines"); textarea.onkeyup = function() { var lines = textarea.value.split("\n"); var start = textarea.selectionStart; var end = textarea.selectionEnd; for (var i = 0; i < lines.length; i++) { if (lines[i].length <= 16) continue; var j = 0; space = 16; while (j++ <= 16) { if (lines[i].charAt(j) === " ") space = j; } lines[i + 1] = lines[i].substring(space + 1) + (lines[i + 1] ? " " + lines[i + 1] : ""); lines[i] = lines[i].substring(0, space); } textarea.value = lines.slice(0, 6).join("\n"); if (start == end) { textarea.setSelectionRange(start, end); } };
But I am not familiar enough with Javascript to get the syntax to work in Forms though. Can anyone help me out?
Thanks!