window.addEventListener('DOMContentLoaded', function() { var x = document.getElementById('id').value; var z = document.getElementById('id2').value; if (x == z) { x.style.color = "green"; } else { z.style.color = "red"; } });