here is an example that verify if the field is empty, but you had not specified what is the type of the button (a submit or regular button) or what should happen after validation (submit the form or just nothing):
Type a user: <input type='text' name='user' />
<input type="button" onclick="if(!form.user.value.length)alert('User is empty');" />
every form's elements have a property named form which is a reference to the form object that contain such element. so, because the code is defined on a function (the event) that is attached to the element, i can use form property without knowing the name of the form or without even doing the long reference document.addTable. however, both way are valid. but always remember that the shortcut form can only be used within the element.
I don't have an alert!
i used it for example purpose, but if that is what you need, then ok.
yes, it does. actually, event are like function declaration. so, you can place as many statement needed and you can use the return statement as in function to prematurely exit the function or cancel the function execution. so, in the code i give, when the field is empty it exit the function without calling the next statement.