document.forms is a collection of all the tags in the page. You can access a particular form either by it’s index position, or it’s name. This code is access the form by name using ["fo"].
.onsubmit is an older way of attaching code to the submit event for the form. HTML elements all have an on* attribute that corresponds to each available event. Assigning a function to these properties will run the function whenever the event occurs.
So, the whole line document.forms["fo"].onsubmit = test; is assigning the test function to the submit event of the form element with name="fo".
Then you need to elaborate more about that. Saying “it doesn’t work” without any other details is not helpful. Did you check your browser’s developer console for errors? Does it show any? If so, what are they. Describe what actually happens vs what you expect to happen, in detail.
The code posted works just fine. If your tests fail, the form isn’t submitted. If they pass, it is submitted (giving a 404 since sub.html doesn’t exist on that server).
According to the flow of your provided code, Your input fields are missing the name attribute, which is typically used to identify form data that gets sent to the server. You might want to add them if you intend to process this data server-side.