Changing of the Firstname's color only works when the string is not empty, It will turn green if there's text but it won't turn red when it's an empty string. How would I be able to do this?
$(document).on("click", '.btn-info.mailContact', function() {
values = {
MailTo: $('.Emailadres').val(),
FirstName: $('.Firstname').val(),
Onderwerp: $('.Subject').val(),
Email: $('.Emailadres').val(),
Tel: 'n.v.t.',
Text: $('.TheMessage').val(),
Comment: 'Comment'
};
if ($('.Firstname').val() != "" && $('.Subject').val() != "" &&
$('.TheMessage').val() != "" && $('.Emailadres').val() != "") {
State.sendContactMail(values);
window.location.href = '/confirmation';
} else {
if (FirstName != "")
FirstName.style.color = "green";
else
FirstName.parents.style.color = "red";
}
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-md-2" >
<strong class="FirstnameTitle">
<span class="text-danger">*</span>
Naam:
</strong>
</div>
<div class="col-md-10">
<input autofocus="autofocus" required="required" type="text"
class="form-control Firstname" id="FirstName" placeholder="Vul je naam hier in"/>
</div>