Trying to improve my javascript code

I confess I have not worked with JSP, but logically having the code block wrapped in a function shouldn’t make any difference to the outcome. I will have another look through your existing code, to see if there is anything I have missed.

I think we could still benefit from seeing the HTML for your form, so we can see how it all ties together. At least that way, we can maybe run some tests.