I running a simple AJAX form that takes an email address to signup to a newsletter then replaces the form with thankyou otherwise it pops up an alert error and the form again.

Initialling I put a peice of code like shown below under the form but it wasn't executed after the AJAX reload like it would on a proper page load.

Code:
<script type="text/javascript">
     alert('error message');
</script>
Therefore I put the code in a function that that either has an alert written in it or its an empty function when there is no error, this function is then called as part of the AJAX complete code. This then does then run the function but it seems to run a cached version of the function as it appeared when the page was first loaded, i.e. empty.

If I use firebug and inspect the function it has the alert but if I actually debug and step into the function it go to the original empty version.

Does anyone know how I can get around this?

Many thanks