diff --git a/app/assets/javascripts/osem.js b/app/assets/javascripts/osem.js index cd1f5304..c0cc7101 100644 --- a/app/assets/javascripts/osem.js +++ b/app/assets/javascripts/osem.js @@ -157,24 +157,27 @@ function word_count(text, divId, maxcount) { } }; -/* Set the minimum and maximum proposal abstract word length */ -$("#event_event_type_id").change(function () { - var $selected = $("#event_event_type_id option:selected") - var max = $selected.data("max-words"); - var min = $selected.data("min-words"); +/* Wait for the DOM to be ready before attaching events to the elements */ +$( document ).ready(function() { + /* Set the minimum and maximum proposal abstract word length */ + $("#event_event_type_id").change(function () { + var $selected = $("#event_event_type_id option:selected") + var max = $selected.data("max-words"); + var min = $selected.data("min-words"); - $("#abstract-maximum-word-count").text(max); - $("#abstract-minimum-word-count").text(min); - word_count($('#event_abstract').get(0), 'abstract-count', max); -}) - .trigger('change'); + $("#abstract-maximum-word-count").text(max); + $("#abstract-minimum-word-count").text(min); + word_count($('#event_abstract').get(0), 'abstract-count', max); + }) + .trigger('change'); -/* Count the proposal abstract length */ -$("#event_abstract").bind('keyup', function() { - var $selected = $("#event_event_type_id option:selected") - var max = $selected.data("max-words"); - word_count(this, 'abstract-count', max); -} ); + /* Count the proposal abstract length */ + $("#event_abstract").bind('change keyup paste input', function() { + var $selected = $("#event_event_type_id option:selected") + var max = $selected.data("max-words"); + word_count(this, 'abstract-count', max); + } ); +}); /* Set the defaults for DataTables initialisation */ $.extend( true, $.fn.dataTable.defaults, {