Please can you help me, i don´t find a solution. I have a function with arguments and want to pass this function to a jquery bind-event:
function countChars23 (chars) {
var thi = $(this);
var len = $(this).val();
if (len.length >= chars) {
len = len.substring(0, 22);
thi.val(len);
}
}
Calling the function don´t work:
$('#name').bind('keyup', countChars23(10));
This don´t work either:
$('#name').bind('keyup', function() {
countChars23(10);
}
This don´t work either:
$('#name').keyup(function() {
countChars23(10);
}
Many Thanks for your help!
You can use the
dataparameter to.bind:and then in your function replace the declared parameter with
eventand put this in the first line:EDIT the reason your second and third attempts (with the extra function wrapper) don’t work is because they don’t set
thisproperly. You would have had to have called it like this: