JavaScript Code
$('body').on('click', '.btn_class', function(event) {
var bnt_cntrl=$(this).attr('id');
var form_elmnt= $(this).parents('form.form1');
var action=form_elmnt.attr("action");
var error_msg_box=form_elmnt.find('.errorBox');
//alert(error_msg_box);
is_done=0;
form_elmnt.find('.errorBox').empty().append('<ol/>');
form_elmnt.find(':input[is_required="1"]:not(:disabled)').each(function(index, element) {
//alert(1);
var type = this.type || this.tagName.toLowerCase();
//alert(type);
if(type=="select-one"){
var currencty_id=$(this).attr("id");
var is_empty=$("#"+currencty_id+" option:selected").val();
}
else{
var is_empty=$(this).val();
}
if(is_empty=="" || is_empty==null || is_empty=='Na' || is_empty=='Null' || is_empty==0){ // if null keyword specified as string
var error_msg=$(this).attr('err_msg');
if(error_msg=="" || error_msg==null || error_msg=='undefined'){ // if your error_msg and placeholder are same then just skip error_msg tag
error_msg = $(this).attr('placeholder');
}
error_msg_box.find('ol').append('<li>'+error_msg+'</li');
is_done++;
//window.scrollTo(0,0);
false;
}
});
if(is_done==0){
var ajaxMsg='';
error_msg_box.empty();
error_msg_box.append("<div class='welcome_msg'><h3>Please wait.form is beinging submited</h3></div>").slideUp(100).slideDown(50);
var form_data=$(form_elmnt).serialize();
ajaxResponce=send_request(bnt_cntrl,'controller/ajax.php',form_data,error_msg_box);
try {
JsonDataSet = JSON.parse(ajaxResponce);
ajaxMsg = JsonDataSet[0];
var ajaxValue = JsonDataSet[1];
} catch(e) {
ajaxMsg=ajaxResponce; // if server return only string
}
if(ajaxMsg=="done"){
var custom_msg='';
if(bnt_cntrl=='add_new_client'){
var timing=1000;
custom_msg="New Client has been added";
error_msg_box.addClass('doneMsg').html(show_done_msg(custom_msg,'?r=add_office&client_id='+ajaxValue+'&lock=1',true,timing)); // page will be redirect after 5 second
$('.redirect_to').html('page will be redirect in '+timing+' milisecond');
}
else if(bnt_cntrl=='add_new_office'){
custom_msg='<h2>New office has been created now.</h2>\
<p>Would you like to add More Offices</p>\
<a href="javascript:void(0)" data-role="yes" id="yes_add_more_office">Yes</a>\
<a href="javascript:void(0)" data-role="no" id="no_more_office">no</a>';
$(this).attr('disabled','disabled');
/*var table_elmnt=$('.add_office_table tbody');
var this_region=form_elmnt.find('#regionBox option:selected').text();
var this_country=form_elmnt.find('#country option:selected').text();
var this_zip=form_elmnt.find('#zip').val();
var this_entity_name=form_elmnt.find('#entity_name').val();
table_elmnt.append(
'<tr>\
<td><!--it will auto append by re_arrange Method --></td>\
<td>'+this_region+'</td>\
<td>'+this_country+'</td>\
<td>'+this_zip+'</td>\
<td>'+this_entity_name+'</td>\
<td><i class="fa fa-minus-circle temp_office_row"></i></td>\
</tr>'
);
var panel_1=form_elmnt.find('.form_elements');
var panel_2=form_elmnt.find('.status_elements');
togglePanel(panel_1,panel_2);
panel_2.html(custom_msg);
re_arrange(table_elmnt,'input[name="is_office_added"]'); */
}
else if(bnt_cntrl=='add_new_employee'){
custom_msg="New employee has been added";
error_msg_box.addClass('doneMsg').html(show_done_msg(custom_msg,'',false,timing)); // page will be redirect after 5 second
//$('.redirect_to').html('page will be redirect in '+timing+' milisecond');
}
//error_msg_box.addClass('doneMsg').html(show_done_msg('sudhir','?r=abcd'));
/*
error_msg_box.addClass('doneMsg').html('<div>\
<i class="fa fa-check-circle bigTick"></i> \
<h2>'+custom_msg+'</h2>\
<i class="btmGap">\
<a href="javascript:void(0)" onclick="javascript:location.reload()">\
Click here to reload page\
</a>\
</i>\
</div>');
*/
$(this).attr('disabled','disabled');
form_elmnt.find('.client_elmnt_box').slideUp(1);
//$('.client_elmnt_box').slideUp(100);
}
else{
error_msg_box.html(ajaxMsg);
return false;
}
}
else{
error_msg_box.show(100);
}
});