if(form.Name.value=='') alert("Name field is required. Please fill it in."); if(form.Address.value=='') alert("Address field is required. Please fill it in."); if(form.Email.value=='') alert("Email field is required. Please fill it in."); if(form.PhoneNumber.value=='') alert("Phone Number field is required. Please fill it in.");
Since form elements reside between the
invoke it when ‘Submit’ button is pressed.
In the above code, instead of hard coding the form’s name (or object name) in the function ‘checkForm’ we are passing it from the form. When any form elements is found to be empty respective message is shown via the Message Box (using alert() ).