I am trying to insert a value into the Database when the value of a Textbox is changed by the User. I have checked the backend code (C#) on its own, without the jQuery and have confirmed that it is working, which leads me to believe that the problem is that the jQuery .change() event is not being fired.
I’ve seen many of the same questions, though none of the solutions seem relevant. How can I get this working?
jQuery:
<script type="text/javascript">
$(function () {
$('.qty').change(function () {
$.post('/InlineEditing.cshtml', { qty: $(this).val(), id: $(this).attr('id') },
function (data) {
alert(data.trim());
});
});
});
</script>
HTML:
<input type="text" class="qty" id="1" value="0" />
If you want to reliably handle text changes, use zurb’s textchanged event instead. This works for keystrokes, paste operations, cut operations etc.
http://www.zurb.com/playground/jquery-text-change-custom-event
Check this demo: http://jsfiddle.net/JnCXG/
Code: