Reputation: 4560
How to use .on on load event more then one time?
var $CartContent = function(){
$Handler = $('#cartHandler');
if($Handler.length > 0){
$Handler.load('cart/content', function(){
$PercentField = $('#item-percent-field');
$PercentField.val(0);
$('.percent-field').val(0);
$PercentField.on('keyup', function(){
var $Value = parseInt($(this).val());
$.each($('.percent-field'), function(index, value){
var $Current = $(this).data('item');
$.post('cart/content', {
id: $Current,
percent: $Value
});
});
});
});
}
};
It work's fine only one time. How to start function load with parameters on every keyup?
Upvotes: 0
Views: 96
Reputation: 382112
You may use the keyup function :
$('#item-percent-field').keyup(function(){
$('#cartHandler').load( ...
...
});
But be sure to have a fast server if you want to load a page on every key up.
Regarding the whole problem, it's not easy to tell what you're trying to do.
First a few remarks :
$CartContent
? Why ?if($Handler.length > 0){
: if empty the following line would simply do nothingUpvotes: 2
Reputation: 16828
I would just move the $PercentField function out altogether and switch to the .live() method, since #item-percent-field won't be created until after the .load is complete
$(function(){
$('#item-percent-field').live('keyup',function(){
var $Value = parseInt($(this).val());
$.each($('.percent-field'), function(index, value){
var $Current = $(this).data('item');
$.post('cart/content', {
id: $Current,
percent: $Value
});
});
})
var $CartContent = function(){
$Handler = $('#cartHandler');
if($Handler.length > 0){
$Handler.load('cart/content', function(){
$PercentField = $('#item-percent-field');
$PercentField.val(0);
$('.percent-field').val(0);;
});
}
});
});
Upvotes: 0