Skip to content

Commit e973eae

Browse files
authored
Create code.js
1 parent e1e98f0 commit e973eae

File tree

1 file changed

+17
-0
lines changed
  • Client-Side Components/Client Scripts/Display a Live Word Count for Description Field

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function onLoad() {
2+
var field = g_form.getControl('description');
3+
var counter = document.createElement('div');
4+
counter.id = 'desc_word_counter';
5+
counter.style.marginTop = '5px';
6+
field.parentNode.appendChild(counter);
7+
8+
field.addEventListener('input', function() {
9+
var wordCount = field.value.trim().split(/\s+/).length;
10+
counter.innerText = 'Word Count: ' + (field.value ? wordCount : 0);
11+
if (wordCount > 150) {
12+
counter.style.color = 'red';
13+
} else {
14+
counter.style.color = 'green';
15+
}
16+
});
17+
}

0 commit comments

Comments
 (0)