$("#form").on("submit", function(){ $.ajax({ url: '/src/login.php', method: 'post', dataType: 'html', data: $(this).serialize(), success: function(data){ $('#message').html(data); } }); }); $('body').on('click', '#password-checkbox', function(){ if ($(this).is(':checked')){ $('#password').attr('type', 'text'); $('#password2').attr('type', 'text'); } else { $('#password').attr('type', 'password'); $('#password2').attr('type', 'password'); } });