function check(emailform) { var valid = true, e1Error = document.getElementById('emailAddress1_error'), email1 = document.emailform.emailAddress1.value; validEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/; if (document.emailform.emailAddress1.value === '') { e1Error.innerHTML = "enter email address"; valid = false; } else if (emailAddress1.value.match(validEmail)) { e1Error.innerHTML = ''; } else { e1Error.innerHTML = "invalid email"; valid = false; } if (valid === true) { // window.alert(1+1); } else { // window.alert(2+2); event.preventDefault(); } } function ccheck(commentform) { var valid = true, cError = document.getElementById('comment_error'), // frm = document.getElementById('commentform').submit(); // frm = document.getElementById('commentform').reset(); frm = document.getElementById('commentform'); if (document.commentform.yourName.value === '' && document.commentform.yourComment.value === '') { cError.innerHTML = "enter your name & comment"; valid = false; } else if (document.commentform.yourName.value === '') { cError.innerHTML = "enter your name"; valid = false; } else if (document.commentform.yourComment.value === '') { cError.innerHTML = "enter comment"; valid = false; } else { cError.innerHTML = ""; } if (valid === true) { // window.alert(1+1); frm.submit(); frm.reset(); } else { // window.alert(2+2); event.preventDefault(); } }