8

I have a textarea in my MVC application where I'm implementing AspNetSpellCheck, the debugger tells me that the textarea changes to display: none; visibility: hidden; and a div is generated with id="abc" and class"="pqr".

<input type="hidden" value="" name="userid" id="useid" />

Also I'm implementing change detection for all text area/other controls....

var somethingChanged = false;
$(document).ready(function() { 
    $('input').change(function() { 
       somethingChanged = true; 
    }); 
});

Because the text area becomes hidden, I suppose it doesn't automatically fire the change() event. What is the solution to fire the event in above case? Thanks!

EDIT

With AspNetSpellCheck, below is my code,

  @{  

  ASPNetSpell.Razor.SpellAsYouType mySpell = new ASPNetSpell.Razor.SpellAsYouType();
   mySpell.InstallationPath = ("/Content/ASPNetSpellInclude");
   mySpell.FieldsToSpellCheck = "TextArea1";
}

<textarea id="TextArea1" cols="20" rows="2">bedddly</textarea>
@Html.Raw(mySpell.getHtml())

<script type="text/javascript" language="javascript">

$(document).ready(function () {
    $('input[type="hidden"]').change(function () {
        debugger;
        alert('hi');
        // somethingChanged = true; 
    });
});


 </script>

Debugger produce below code, text area hidden and a new DIV construct,

 <div tabIndex="null" class="livespell_textarea" id="TextArea1___livespell_proxy">

 <textarea id="TextArea1" style="display: none; visibility: hidden;" rows="2" cols="20">
user584018
  • 10,186
  • 15
  • 74
  • 160
  • duplicate of http://stackoverflow.com/questions/6533087/jquery-detect-value-change-on-hidden-input-field – Daniel P Sep 27 '13 at 15:32

3 Answers3

15

With hidden values, you'll need to trigger the change event yourself ala:

$('#hiddenInput').val('newval').trigger('change');
user1026361
  • 3,627
  • 3
  • 22
  • 20
5

if you dont know when the value is being changed in the textarea you can use setInterval to moniter the change

Eg

  var objTextBox = document.getElementById("your_id");
  oldValue = objTextBox.value;

  function track_change() {
    if (objTextBox.value != oldValue) {
      oldValue = objTextBox.value;
      alert('value of input has changed');
    }
  }

  setInterval(function () {
    track_change()
  }, 1000);
Faizan Ahmad
  • 355
  • 3
  • 14
GajendraSinghParihar
  • 9,051
  • 11
  • 36
  • 64
2

Try this.. Trigger the event Yourself

$('input[type="hidden"]').change(function() { 
     alert('hi');
      // somethingChanged = true; 
});

$('#useid').val("20").change();

FIDDLE

Sushanth --
  • 55,259
  • 9
  • 66
  • 105