Looking a little closer at your script block, I see that the event handler is added by myFunction(), but you never actually call myFunction() to apply the handler.
If you need myFunction() (namely, if you have a default behavior for the field that needs to be preserved) then make sure to tie in control functionality for it.
If you don't need it, then just place the handler assignment directly into the script block, like so:
<script>
$(document).ready(function(){
$("#InvoiceNo").keypress(function (e) {
$.ajax({
url: '@Url.Action("IsInvoiceExists", "Home")',
data: e.target.value,
type: "POST",
cache: false,
success: function (data) {
if (data == 0) {
$("#msgbox").fadeTo(200, 0.1, function () {
$(this).html('This Invoice Already exists').addClass('messageboxerror').fadeTo(900, 1);
});
}
else if (data == 1) {
$("#msgbox").fadeTo(200, 0.1, function () {
$(this).html('Invoice available').addClass('messageboxok').fadeTo(900, 1);
});
}
else {
alert("Some error occured! Check Console");
}
},
error: function (xhr) {
}
});
});
});
</script>