$(function(){ var that = this; that.initAdd = function(){ $('.add_newsletter').on('click', function(){ var property = { 'ajax': 1, 'token': token_newsletter, 'action': 'addForm', }; $.ajax({ type: 'GET', url: currentIndex, dataType : "json", data : property, success: function(data) { if(data.hasError) { displayError(data.error); } else { $.fancybox(data); } }, error: function() { displayError('An error occured in PHP'); } }); }); $('body').on('submit', '#form_add', function(){ if($(this).find('input[name=name]').val() == '') { displayError('Input newsletter name'); return false; } }); } that.init = function(){ that.initAdd(); } $(document).ready(function(){ that.init(); }) });