i have call function on onkeyup event of textbox which pass the data using ajax.below is sample code of my function which in .js file.
var timeout;
function testfont(id,image)
{
alert('image');//when alert here it shows value
clearTimeout(timeout);
timeout = setTimeout( function()
{
if(image.match(/_small/g))
{
var image = image.replace('_small','');
} else {
var image = image;
}
alert('image'); //when alert here it show undefined
}, 500);
}
But the problem is that i get the image value undefined inside setTimeout function.it works perfectly without use of setTimeout but i need setTimeout function for event fire after some time.
how can i resolve this?
You are making variables in each of your condition.