title: JS detect HTML input field value change (unusual scenario)
body: <p><strong>Background</strong>: A website required a unique mutli-select tool where a user clicks on a text input, which launches a modal popup containing a series of selectable checkboxes.  When that modal is closed, either via clicking &quot;Save&quot;, the X in the top-right, or simply outside of the modal, their selection is stored to the text input field.</p>
  <p>Here is a basic example of this in JSFiddle: <a href="https://jsfiddle.net/6x7ur3k2/1/" rel="nofollow noreferrer">https://jsfiddle.net/6x7ur3k2/1/</a></p>
  <p><strong>Goal</strong>: I now have a need to determine when the user has changed this particular input text field's value.  So if the text field lists &quot;A, B&quot; when the user clicks to launch the modal, then changes to selection to anything other than A, B, the system will detect this.  As such some of the methods of detecting input field value changes with which I am familiar do not work here since it JS,not the user, changing the value.</p>
  <p><strong>Problem:</strong> My initial attempt to accomplish this contained two event handlers, one attached to clicking on the text input that stores it's value to a variable, then another attached to when the modal is closed which compares the first value to the new value and checks for differences.  This doesn't work, however.  Additionally, each time the user clicks on the input text field, a new event is attached the closing of the modal, and I haven't figured out how to end that using off() without also removing the event handler that stores the selected checkboxes as values in the text input fields when the modal is dismissed/closed. This is the code on line 5 of the JSFiddle JS portion <code>$('.list-modal').on('hide.bs.modal', function () {</code></p>
  <p>Here is an example of the code I tried to detect the change.  In addition to always indicating the value has changed, it appears to stack new event handlers on modal closure.</p>
  <pre><code>        $('#preset-work-area').on('click', function() {
              var content = $('#preset-work-area').val();
              $('#preset-work-area-modal').on('hide.bs.modal', function () {
                  if ($('#preset-work-area').val() != value) {
                      alert('Text input values have changed'));
                  }
              });
          });
  </code></pre>
  <p>If I include <code>$('#preset-work-area').off();</code>, it breaks the functionality of <code>$('.list-modal').on('hide.bs.modal', function () {</code> which stores the user's checkbox selections to the input field on modal closure.</p>
  <p>Any help or assistance here would be greatly appreciated.</p>