The first argument to setTimeout is a function. So wrap your code inside an anonymous function, and you're good to go.
$("form.stock").submit(function(){ // Example Post $.post($(this).attr('action'), { id: '123', stock: '1' }); var submit = $(this).find(":submit").attr('value','Saved!'); //Creating closure for setTimeout function. setTimeout(function() { $(submit).attr('value','Update') }, 2000); return false; });
I can not check this code right now. Let me know if this doesn't work.
EDIT: As redsquare suggested, it makes sense to create a closure from the submit button itself.
SolutionYogi
source share