Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect value change on hidden input field

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">
like image 967
user584018 Avatar asked Oct 04 '12 16:10

user584018


People also ask

How do you find the change field input?

Answer: Use the input Event You can bind the input event to an input text box using on() method to detect any change in it. The following example will display the entered value when you type something inside the input field.

How do you assign a value to a hidden field?

In jQuery to set a hidden field value, we use . val() method. The jQuery . val() method is used to get or set the values of form elements such as input, select, textarea.

Are hidden inputs submitted?

Even though the hidden input cannot be seen at all, its data is still submitted.


1 Answers

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

$('#hiddenInput').val('newval').trigger('change');
like image 74
user1026361 Avatar answered Oct 13 '22 04:10

user1026361