I would use Server Validation and a WebAssist Recordset to do it and then you would have access to the server behaviors for adding messages and retaining entered values that come with it.
I helped you manipulate your hand code, but really doing it with the server behaviors to begin with would allow you the functionality you need.