I was wondering if I can do this with Javascript:

I have a form and want to validate the name and email. If everything is good I need a confirm dialog box in the dialog box I want a choice to submit a php page or to cancel. If the validate fails I need it to go back to the form and put focus on the input field that was wrong. If anyone can let me know what I need to do or how I would go about doing this I would greatly appreciate it.

Thank you in advance.