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">
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.
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.
Even though the hidden input cannot be seen at all, its data is still submitted.
With hidden values, you'll need to trigger the change event yourself ala:
$('#hiddenInput').val('newval').trigger('change');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With