Posted in Javascript, JQuery

Jquery – AJAX Post()

function writeLog (lquestionnaire, lversion, ltak){

var activity = “EVALUATION – Questionnaire: ” + lquestionnaire + ” Version: ” + lversion + ” Branch: ” + ltak

$.post(‘inl_sev_067_J_skp.php’, {“ACTIVITY” : activity}, function(response) {

}, ‘json’)

}

Posted in Javascript, JQuery, SQL

Populate select 2 with JSON data

BranchSelect

function getTak (questionnaire, version) {

$(‘#_TAK’).children(‘option:not(:first)’).remove();

$.post(‘inl_sev_055_J_nvg.php’,{“QUESTIONNAIRE” : questionnaire, “VERSION” : version}, function(data) {

var i;

for (i = 0; i < data.length; i++) {

text = data[i];

newOption = new Option(text, i, false, false);

$(‘#_TAK’).append(newOption).trigger(‘change’);

}

}, ‘json’);

}


 

// — Parameters input ——————————————————–

$questionnaire = (isset($_REQUEST[‘QUESTIONNAIRE’])) ? $_REQUEST[‘QUESTIONNAIRE’] : ”;
$version = (isset($_REQUEST[‘VERSION’])) ? $_REQUEST[‘VERSION’] : ”;

// — Define containers ——————————————————-

$terugvoer = array();

// — Retrieve the present list of versions ———————————–

$sql = “SELECT DISTINCT _TAK FROM questionnaire WHERE _TEMPLATE = ‘$questionnaire’ AND _VERSION = ‘$version’ “;

$db = new MysqliDb(‘CES’);

$selectStatus = $db->rawQuery($sql);

if ($selectStatus > 0) {

foreach ($selectStatus as $row) {

$terugvoer[] = $row[‘_TAK’];

}

}

echo json_encode($terugvoer);

?>

Posted in Javascript, JQuery

Select 2 handlers defined at page load

$(‘#_QUESTIONNAIRES’).on(‘select2:select’, function (e) {

var data = e.params.data;

myQuestionnaire = data.text;

getVersion (myQuestionnaire); 

$(‘#label_versionlist’).show();

$(‘#_VERSIONS’).next().show();

});

// ——————————————————

$(‘#_VERSIONS’).on(‘select2:select’, function (e) {

$(‘#label_branchlist’).show();
$(‘#_TAK’).next().show();

var data = e.params.data;

myVersion = data.text;

});

// ——————————————————

$(‘#_TAK’).on(‘select2:select’, function (e) {

document.getElementById(“btnEvaluasiestaat”).disabled = false;

var data = e.params.data;

myBranch = data.text;

});

 

function getVersion (questionnaire) {

$(‘#_VERSIONS’).children(‘option:not(:first)’).remove();

$.post(‘inl_sev_042_J_nvg.php’,{“QUESTIONNAIRE” : questionnaire}, function(data) {

var i;

for (i = 0; i < data.length; i++) {

text = data[i];

newOption = new Option(text, i, false, false);

$(‘#_VERSIONS’).append(newOption).trigger(‘change’);

}

}, ‘json’);

}