(function($) { var rating = $('#wp_review_comment_rating'); $('body').on('submit', '#commentform', function(e) { if (rating.val() === '0') { alert('Please select a rating!'); e.preventDefault(); } }); })(jQuery);