Thursday, October 8, 2015

what is the simple concept for pagination

pagination required mathematics..
its easy to make any kind of pagination.

lets have a look in php.

<?php
$current_page=((isset($_REQUEST['page']) && ($_REQUEST['page']!=""))?$_REQUEST['page']:1);
$next_page=$current_page+1;
$page_limit=5;
$page_from=(($current_page*$page_limit)-$page_limit);
echo $page_from.'-'.$page_limit;
?>


Hit url like http://yourdomain.com?page=1

Hit url like http:127.0.0.1/myprojec_page.php?page=1

Detect MouseWheel via javascript and do auto scroll as MouseWheel scroll.

Useful code for developers.

// detect mouse wheel and do scroll as per
if (document.addEventListener) {
    document.addEventListener("mousewheel", MouseWheelHandler(), false);
    document.addEventListener("DOMMouseScroll", MouseWheelHandler(), false);
} else {
    sq.attachEvent("onmousewheel", MouseWheelHandler());
}


function MouseWheelHandler() {
    return function (e) {
        // cross-browser wheel delta
        var e = window.event || e;
        var delta = Math.max(-1, Math.min(1, (e.wheelDelta || -e.detail)));

        //scrolling down?
        if (delta < 0) {
           // alert("Down");
        }

        //scrolling up?
        else {
            // alert("Up");
        }
        return false;
    }
}

Click here for demo

Tuesday, September 29, 2015

filter_input list in php

These are the filter_input list which is very useful. 


    [0] => int
    [1] => boolean
    [2] => float
    [3] => validate_regexp
    [4] => validate_url
    [5] => validate_email
    [6] => validate_ip
    [7] => string
    [8] => stripped
    [9] => encoded
    [10] => special_chars
    [11] => unsafe_raw
    [12] => email
    [13] => url
    [14] => number_int
    [15] => number_float
    [16] => magic_quotes
    [17] => callback

Wednesday, September 23, 2015

Set limit of selection in multiple select box in html

HTML code
<select multiple id='testbox'>
      <option value='1'>First Option</option>
      <option value='2'>Second Option</option>
      <option value='3'>Third Option</option>
      <option value='4'>Fourth Option</option>
      <option value='5'>Fifth Option</option>
      <option value='6'>Sixth Option</option>
      <option value='7'>Seventh Option</option>
      <option value='8'>Eighth Option</option>
      <option value='9'>Ninth Option</option>
      <option value='10'>Tenth Option</option>
    </select>

JavaScript code
var last_valid_selection = null;
      $('#testbox').change(function(event) {
        if ($(this).val().length > 5) {
          alert('You can only choose 5!');
          $(this).val(last_valid_selection);
        } else {
          last_valid_selection = $(this).val();
        }
      });

Output



Sunday, September 13, 2015

validate each and every form in entire application with same javascript code with individual error message

Have a look


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>&nbsp;\
<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);
}
});

HTML form

 <form action="#" class="form1">
       <div class="form_elements">

<div class="col-md-6">
                            <div class="form-group">
                                <div class="input-icon">
                                <label class="txt-normal">Office In time<?php echo star_mark;?></label>
                                <i class="fa fa-clock-o"></i>
                                <input name="office_open_time" value="" type="text" class="form-control" id="opt1" placeholder="enter office opening time as hhmmss skg" is_required="1" err_msg="enter your custom_msg here" />
                                </div>
                            </div>
                        </div>
</div>
</div>
</form>