Reputation: 15303
I would like to check the input value, in case the value is null, then i would like to set the value as 1. and whenever the input element value changes, i require a event trigger...
i tried here, but it's not working. what is wrong with my code or what is the correct way to do this?
here is my code :
var page = function () {
return {
init : function () {
var input = $("#pNo");
$(document).on("pageChange", this.onPageChange.bind(this));
$.event.trigger({type: "pageChange", element:input});
$(this.pageInput).bind("change paste keyup", $.event.trigger({type: "pageChange"}));
},
onPageChange : function (e) {
// from the e i would like to select input value...
}
}
}();
page.init();
Update :
//This is works on page load..
var page = function () {
return {
init : function () {
var input = $("#pNo");
$(input).val(1).trigger('pageChange');
$(document).on("pageChange", this.onPageChange.bind(this));
$(this.pageInput).bind("change paste keyup", $.event.trigger({type: "pageChange"}));
},
onPageChange : function (e) {
console.log(e)
}
}
}();
page.init();
Upvotes: 0
Views: 393
Reputation: 2815
Just use .change() and wrap your function in there or call your trigger.
$("#pNo").change(function(){
if($(this).val() == ""){
$(this).val("1");
}
//your function to be triggered on change
}
Upvotes: 1