Saturday, August 24, 2013

Change a variable value inside a Jquery .filter() function

Change a variable value inside a Jquery .filter() function

I have a table which has id 'myTable'. Now there is a textbox in which I
write down the item name to find whether it exists in the myTable cell or
not. To do this I have written the following code -
var retval=0;
var search = $("#searchitem").val().trim();
$("table#myTable tr td").filter(function() {
if($(this).text() == search){retval=1;alert('Same item found');}
else{retval=0;}
});
The problem is that, when it finds the same item in the table cell it
shows the alertbox. But the value of my variable retval never changes. It
always shows 0. How can I solve it?

No comments:

Post a Comment