0

Here, I supposed to click the checkboxes then I send the data into database using submit button (AJAX). After click on submit button, it will be refresh the page but all the selected checkboxes gone. How I do to keep the selected checkboxes after refresh the page? Any idea or guide to do it?

AJAX

//AJAX call for button
    $("#primaryTextButton").kendoButton();
    var button = $("#primaryTextButton").data("kendoButton");
    button.bind("click", function(e) {

    var test = $("#dropdown").val()

    $.ajax({
        url: "../DesignationProgramTemplate/getTemplate.php",
        type: "post",
            data: {'id':test,'progid':array},
                success: function () {
                // you will get response from your php page (what you echo or print)                 
                    kendo.alert('Success'); // alert notification
                    //refresh
                    //location.reload("http://hq-global.winx.ehors.com:9280/ehors/HumanResource/EmployeeManagement/DesignationProgramTemplate/template.php");
                },
        });
    });

PHP for getTemplate

$employeeID = $_SESSION['employeeID'];
$propertyID = $_SESSION['propertyID'];
$id = $_POST['id'];
$progid = $_POST['progid'];

for($x=0; $x< sizeof($progid); $x++ )
{
    $array = array();   

$positionTemplateID = $ehorsObj->EHORS_PK("tblHrsPositionProgramTemplate"); 
$sqlAdd = "INSERT INTO tblHrsPositionProgramTemplate 
            SET positionTemplateID = '" . $positionTemplateID . "',
            programID = '" . $progid[$x] . "',
            hrsPositionID  = '" . $id . "',
            propertyID   = '" . $propertyID . "',
            employeeID  = '" . $employeeID . "',
            dateTimeEmployee = NOW() ";     

$ehorsObj->ExecuteData($sqlAdd, $ehorsObj->DEFAULT_PDO_CONNECTIONS);

$positionTemplateIDLog = $ehorsObj->EHORS_PK("tblHrsPositionProgramTemplateLog");   
$sqlAddLog = "INSERT INTO tblHrsPositionProgramTemplateLog 
            SET positionTemplateIDLog = '" . $positionTemplateIDLog . "',
            positionTemplateID = '" . $positionTemplateID . "',
            programID = '" . $progid[$x] . "',
            hrsPositionID  = '" . $id . "',
            propertyID   = '" . $propertyID . "',
            employeeID  = '" . $employeeID . "',
            dateTimeEmployee = NOW() ";     

$ehorsObj->ExecuteData($sqlAddLog, $ehorsObj->DEFAULT_PDO_CONNECTIONS);
}

Function for checkboxes

function checkedNodeIds(nodes, checkedNodes) {
  for (var i = 0; i < nodes.length; i++) {
    if (nodes[i].checked) {
      //checkedNodes.push(nodes[i].moduleID);
     // checkedNodes.push(nodes[i].groupID);
      checkedNodes.push(nodes[i].id);
    }

    if (nodes[i].hasChildren) {
      checkedNodeIds(nodes[i].children.view(), checkedNodes);
    }
  }

}

Checkboxes check

function toggleCheckAll() {
        var checkButtonValue = $("#chbAll").val();

        if(checkButtonValue == "Uncheck"){
          $("#AccountingTree .k-checkbox-wrapper input").prop("checked", true).trigger("change");
          $("#AdminSystemTree .k-checkbox-wrapper input").prop("checked", true).trigger("change");

          $("#chbAll").val("Check");
        } else {
          $("#AccountingTree .k-checkbox-wrapper input").prop("checked", false).trigger("change");
          $("#AdminSystemTree .k-checkbox-wrapper input").prop("checked", false).trigger("change");

          $("#chbAll").val("Uncheck");

        }

}

HTML

<div class="selectAll">
  <input type="checkbox" id="chbAll" value="Uncheck" class="k-checkbox" onchange="toggleCheckAll()" />

  <label class="k-checkbox-label" for="chbAll">Select All</label>

Anyone have the idea about it?

Output

HelpMe
  • 21
  • 5

1 Answers1

0

With this you can save the checked boxes, remember its with GET method.


<html>

<body>

<form method="get" action="">

    <input type="checkbox" name="vehicle1" value="Bike"> I have a bike<br>
    <input type="checkbox" name="vehicle2" value="Car"> I have a car<br>
    <input type="checkbox" name="vehicle3" value="Boat"> I have a boat<br>

    <input type="submit" name="submit">

</form>

</body>

    <script>

        var a = window.location.search.substr(1).split('&');
        console.log(a);
        function test(value, index){ a[index] = value.split("="); }
        function test2(value, index){ console.log(document.getElementsByName(value[0])); document.getElementsByName(value[0])[0].checked = true; }
        a.forEach(test);
        a.forEach(test2);

    </script>

</html>

deon cagadoes
  • 582
  • 2
  • 13