var App_GiftCard_Form = { init: function(formId) { var obj = this; $('#newCardCode').click(function() { obj.genCardCode(); }); $('#btnSubmit').click(function() { $('#send').val(''); }); $('#btnSend').click(function() { $('#send').val('y'); }) }, genCardCode: function() { var deferred = qs.ajax(qs.constant('BASE_URL') + '/' + qs.constant('CURRENT_PAGE'), {action: 'generateCode'}); deferred.done(function (data) { var code = ''; if (data.code) { code = data.code; } else { alert('Code is not created.'); } $('#cardCode').val(code); }); } };