var arr_form = ['family', 'name', 'date', 'select', 'email', 'phone', 'text']; arr_form.forEach(function(name) { var element = document.getElementsByName(name)[0]; $(element).change(function(){validname($(element))}); });