I want a function to be run when a keypress occurs on a text box, so I have this code:
$(\"input[x]\").keypress(function() { DoX(); })
Use setTimeout without a delay. It will run immediately after keypress event completes so you'll have the correct value of the input.
$("input[x]").keypress(function() { setTimeout(DoX); });