If-else code which I have written. I want to optimize it.
(Using maybe Collection).
Can someone show me how to do it?
if(form.first_name.value == '' && form.last_name.value == '' && form.company.value == '' && form.email.value == '') {
document.getElementById("fn").style.display = 'block';
document.getElementById("ln").style.display = 'block';
document.getElementById("cmp").style.display = 'block';
document.getElementById("em").style.display = 'block';
return false;
}
else if(form.first_name.value == '' && form.last_name.value == '' && form.company.value == ''){
document.getElementById("fn").style.display = 'block';
document.getElementById("ln").style.display = 'block';
document.getElementById("cmp").style.display = 'block';
return false;
}
else if(form.first_name.value == '' && form.last_name.value == '' && form.email.value == ''){
document.getElementById("fn").style.display = 'block';
document.getElementById("ln").style.display = 'block';
document.getElementById("em").style.display = 'block';
return false;
}
else if(form.first_name.value == '' && form.company.value == '' && form.email.value == ''){
document.getElementById("fn").style.display = 'block';
document.getElementById("cmp").style.display = 'block';
document.getElementById("em").style.display = 'block';
return false;
}
else if(form.last_name.value == '' && form.company.value == '' && form.email.value == ''){
document.getElementById("ln").style.display = 'block';
document.getElementById("cmp").style.display = 'block';
document.getElementById("em").style.display = 'block';
return false;
}
else if(form.first_name.value == '' && form.last_name.value == ''){
document.getElementById("fn").style.display = 'block';
document.getElementById("ln").style.display = 'block';
return false;
}
else if(form.first_name.value == '' && form.company.value == ''){
document.getElementById("fn").style.display = 'block';
document.getElementById("cmp").style.display = 'block';
return false;
}
else if(form.first_name.value == '' && form.email.value == ''){
document.getElementById("fn").style.display = 'block';
document.getElementById("em").style.display = 'block';
return false;
}
else if(form.last_name.value == '' && form.company.value == ''){
document.getElementById("ln").style.display = 'block';
document.getElementById("cmp").style.display = 'block';
return false;
}
else if(form.last_name.value == '' && form.email.value == ''){
document.getElementById("ln").style.display = 'block';
document.getElementById("em").style.display = 'block';
return false;
}
else if(form.company.value == '' && form.email.value == ''){
document.getElementById("cmp").style.display = 'block';
document.getElementById("em").style.display = 'block';
return false;
}
else if(form.first_name.value == ''){
document.getElementById("fn").style.display = 'block';
return false;
}
else if(form.last_name.value == ''){
document.getElementById("ln").style.display = 'block';
return false;
}
else if(form.company.value == ''){
document.getElementById("cmp").style.display = 'block';
return false;
}
else if(form.email.value == ''){
document.getElementById("em").style.display = 'block';
return false;
}