jquery not firing after form submit with ajax
Hi,
The code below works GREAT on form page load and typing into "test_field". The number of characters left display correctly in "
display_char_left"
So all is good until AFTER the form is submitted. After saving the form, ajax is used to refresh page (save data) and display form again with the same field data. Now, the countChar() is never fired again.
How do you make the countChar function continue to execute/work AFTER saving the form, when ajax is used to refresh the page? thanks
- <script>
- var maxLength = 40;
- function countChar() {
- var length = $('#test_field').val().length;
- length = maxLength-length;
- jQuery('#display_char_left').text(length);
- };
-
- jQuery(document).ready(function($) {
- $("#test_field").on('load', function() {
- countChar(); });
- $("#test_field").on('propertychange', function() {
- countChar(); });
- $("#test_field").on('keyup', function() {
- countChar(); });
- $("#test_field").on('input', function() {
- countChar(); });
- $("#test_field").on('paste', function() {
- countChar(); });
-
- countChar();
- });
- </script>