Reputation: 2803
I'm trying to use an jquery keyup event. But i can't get it to trigger correctly. It seems to only hit then i use the mouse to click out side the input field. I can't find why it won't work correctly.
HTML:
<input type="text" class="form-control requiredField validateField translateString " id="ReportInternalOrderTxt" data-isvalid="false">
Javascript:
$(document).off("keyup", "#ReportInternalOrderTxt").on("keyup", "#ReportInternalOrderTxt", function (e) {
var result = parseInt($("#ReportInternalOrderTxt").val());
$("#ReportInternalOrderTxt").attr("data-isvalid", (typeof result === "number" && (result % 1) === 0) && result > 0);
});
Upvotes: 0
Views: 555
Reputation: 207517
I think you just confused everyone thinking that the keyup was not working when in reality you are talking about the validation not trigger until you blur the element. That is because the validaion is waiting for onchange to fire which happens when blur occurs. So you need to trigger it manually after setting the data attribute.
$(document).off("keyup.numValidate").on("keyup.numValidate", "#ReportInternalOrderTxt", function (e)
var textbox = $(this);
var result = parseInt(textbox.val(), 10);
textbox.attr("data-isvalid", (typeof result === "number" && (result % 1) === 0) && result > 0);
textbox.change(); // or textbox.trigger("change");
});
Upvotes: 1
Reputation: 352
This is what you need:
$('#ReportInternalOrderTxt').keyup(function(){
//Your code
});
Upvotes: 0