<!DOCTYPE html>
<!--
aryx, 2018 | GAMF
-->
#form-field {
margin:10px;
}
#form-field label {
width:150px;
display:inline-block;
}
input[type=text], input[type=email], textarea {
border:1px solid red;
}
<body onload="document.getElementById('submit').disabled = 1;">
<form onsubmit="return ellenoriz()">
<input type="text" name="name" id="name">
<input type="email" name="email" id="email">
<input type="button" value="ellenoriz()" onClick="ellenoriz();">
<input type="submit" value="Küldés" id="submit">
function ellenoriz() {
var in_name = document.getElementById('name');
var in_mail = document.getElementById('email');
var in_msg = document.getElementById('message');
var checkPattern = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var name_jo = false;
var mail_jo = false;
var msg_jo = false;
if (in_name.value.length >= 5) {
in_name.style="background-color:#96ff9f;";
console.log("jó a név");
name_jo = true;
} else {
in_name.style="background-color:#ff8e8e;";
console.log("nem jó a név");
}
if (checkPattern.test(in_mail.value) === true) {
in_mail.style="background-color:#96ff9f;";
console.log("jó az email");
mail_jo = true;
} else {
in_mail.style="background-color:#ff8e8e;";
console.log("nem jó az email");
}
if (in_msg.value.length >= 1) {
in_msg.style="background-color:#96ff9f;";
console.log("jó az üzenet");
msg_jo = true;
} else {
in_msg.style="background-color:#ff8e8e;";
console.log("nem jó az üzenet");
}
if (name_jo === true && mail_jo === true && msg_jo === true) {
document.getElementById('submit').disabled = 0;
return true;
} else {
document.getElementById('submit').disabled = 1;
return false;
}
}