How to Increment value clicking plus minus icon in Jquery?

Html Code:

<div class="csdisplayorder" >
    <span class='csminus glyphicon glyphicon-minus'></span>
    <input class="cscurrent" type="text" disabled value="1" data-rid="1" data-pid="2">
    <span class='csplus glyphicon glyphicon-plus'></span>
</div>

Script:

<script type="text/javascript">
$(document).ready(function(){
    $('.csdisplayorder .csplus').live('click', function(){
        var dis = $(this);
        var input_obj = dis.parent().find('.cscurrent');
        var input_val = parseInt(input_obj.val());
        if(input_val == undefined){
            input_obj.val(0);
        }else{
            var new_val =  parseInt(input_val)+1;
            input_obj.val(new_val);
            $(this).fncsUpdateRoomDisplayOrder(dis, new_val);
        }
    });

    $('.csdisplayorder .csminus').live('click', function(){
        var dis = $(this);
        var input_obj = dis.parent().find('.cscurrent');
        var input_val = parseInt(input_obj.val());
        if(input_val == undefined){
            input_obj.val(0);
        }else{
            if(parseInt(input_val) >0){
                var new_val =  parseInt(input_val)-1;
                input_obj.val(new_val);

                $(this).fncsUpdateRoomDisplayOrder(dis, new_val);
            }
        }
    });

    $.fn.fncsUpdateRoomDisplayOrder = function(dis,nval) { 
        var input_obj = dis.parent().find('.cscurrent');
        var rid = input_obj.data('rid');
        var pid = input_obj.data('pid');

        var datastring = {'nval':nval,'rid':rid,'pid':pid}
        var xhrequest = false;
        xhrequest = $.ajax({
            url: base_url+'update',
            type:'post',
            dataType: 'json',
            data:datastring,
            async:false, 
            beforeSend: function (){
                if (xhrequest) {
                    xhrequest.ajaxStop();
                    console.log("xhrequest");
                }
            },
            success: function(data){
                xhrequest = false;
                console.log(data);
            }
        });
    }
});
</script>

CSS:

<style type="text/css">
.csdisplayorder{width: 62px;text-align: center;}
.csdisplayorder .cscurrent{width: 25px;float: none;background-color: white;border: none;text-align: center;}
.csdisplayorder .csplus,.csminus{padding: 3px;background-color: grey;color: white;border-radius: 10px;}
.csdisplayorder .csminus{float: left; }
.csdisplayorder .csplus{float: right;}
.csdisplayorder .cscurrent_txt{width:25px;float:none;vertical-align:-webkit-baseline-middle;vertical-align: sub;}
.csdisplayorder input[type=number].cscurrent::-webkit-inner-spin-button, 
.csdisplayorder input[type=number].cscurrent::-webkit-outer-spin-button { 
  -webkit-appearance: none; margin: 0; }
</style>

This page isn’t working Chrome detected unusual code on this page and blocked it to protect your personal information. ERR_BLOCKED_BY_XSS_AUDITOR

This page isn't working
Chrome detected unusual code on this page and blocked it to protect your personal information (for example, passwords, phone numbers, and credit cards).
ERR_BLOCKED_BY_XSS_AUDITOR




This page isn’t workingERR_BLOCKED_BY_XSS_AUDITOR

Mainly,

This error message is occurs when we are trying to post a content with HTML tags or Scripts Tags or Like When Google Chrome believes a “cross-site scripting” attack is happening. These attacks happen when a browser is tricked into rendering HTML or JavaScript that is not meant to be a part of the website being displayed.

Then Chrome Generates This ERROR ”
ERR_BLOCKED_BY_XSS_AUDITOR

For PHP and All Other PHP Frameworks: Add this below line before post

 header('X-XSS-Protection:0'); 

Print the Div Contents in Php or Javascript

The JavaScript is below..

<script type="text/javascript">
var base_url="<?php echo $this->request->webroot; ?>";

function printDivContents(divID="xshr_print_section") {

    //Get the HTML of div
    var divElements = document.getElementById(divID).innerHTML;
    
    Popup(divElements);
}


function Popup(data) {
    var mywindow = window.open('', 'new div', 'height=400,width=600');
    mywindow.document.write('<html><head><title></title>');
    mywindow.document.write('<link rel="stylesheet" href="'+base_url+'"css/print.css" type="text/css" />');
    mywindow.document.write('</head><body >');
    mywindow.document.write(data);
    mywindow.document.write('</body></html>');

    mywindow.print();

    return true;
}
</script>

The HTML file is like-

<div id="xshr_print_section">
<!-- here the printing Contents -->

-
-
-
</div> 

PHP – Foreach Pass-by-Reference ? Do it now!

Normally, when we are using the “Pass-By-Reference” in the foreach block we write code like below..

foreach ($array as &$row) {
// we Just Do Our stuff
}

We Must Have to “Unset” when we use “Pass-by-Reference”. Otherwise the array data may be altered. So, BEWARE.!

foreach ($array as &$row) {
// We Just Do Our stuff

// Now Unset after the Stuff
unset($row);
}

Don’t forget to “unset” the reference variable after the loop.

//---------------------------------
// Normally we do
//---------------------------------

$main_array = array('1','2','3','4');
$sub_array = array('11','22','33','44');


print_r($main_array);

print_r($sub_array);


/*
# Actual Array Data:
Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
)
*/

$main_text = "";
foreach($main_array as &$row) {
    $main_text .= $row.',';

}

$sub_text = "";
foreach($sub_array as $row) {
    $sub_text .= $row.',';
}


print_r($main_array);

print_r($sub_array);



/*

# (main_array) Altered Data:

Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 44
)

# (main_array) Expected Data:

Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
)
*/

//-------------------------------
//	We Have to Use Like this
//-------------------------------

$main_text = "";
foreach($main_array as &$row) {
    $main_text .= $row.',';

    //Unset the pass-by-reference variable
    unset($row);
}

/*
// Now the Result will not altered

Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
)
*/

This is because when the second loop executes, $row is still a pass-by-reference variable.
Thus, with each iteration the original reference is overwritten.