Этот JavaScript проверяет, пусто ли поле name-text
.Как добавить текст в текстовое поле
Если пустая, то одна и та же строка должна содержать «Имя требуется».
function checkFields(){
var name = document.forms["contact-form"]["name"].value;
if(name == ""){
}
<!--- This is the html code for text box for name and submit button to call checkFields() method -->
<div class="required-fields">
<label>My Name:</label>
<input type="text" name="name"/>
</div>
<input type="button" onclick="checkFields()" value="Send Message"/>
https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Forms/Data_form_validation – epascarello