Posted in HTML, Javascript

Javascript – Validating text input

</td><td><textarea rows=”2″ name=_CANCOMMENT’ + item.quest_id + ‘ id=_CANCOMMENT’ + item.quest_id + ‘ onkeyup = “Validate(this)” ‘ + ‘ onblur = “updateDetail(‘ + item.quest_id + ‘,’ + item._ACTUALPOINTS + ‘)” ‘ + ‘” class=”input-field control form-control” style=”width:400px”>’ + item._CANCOMMENT + ‘</textarea> </td>’

 


 

function Validate(txt) {

txt.value = txt.value.replace(/[^a-zA-Z 0-9\n\r]+/g, ”);

}

Posted in HTML, Javascript

Textarea – Input

<td><textarea rows=”2″ name=_CANCOMMENT’ + item.quest_id + ‘ id=_CANCOMMENT’ + item.quest_id + ‘ onkeyup = “Validate(this)” ‘ + ‘ onblur = “updateDetail(‘ + item.quest_id + ‘,’ + item._ACTUALPOINTS + ‘)” ‘ + ‘” class=”input-field control form-control” style=”width:400px”>’ + item._CANCOMMENT + ‘</textarea> </td>’


 

function updateDetail (isn, outof) {

var cancommenttextarea = “_CANCOMMENT” + isn;

var cancomment = $(‘textarea[name=’ + cancommenttextarea + ‘]’).val(); 

Posted in Javascript, PHP, SQL

PHP – SQL data stored in array passed to javascript

// — Retrieve the list of categories —————————————–

$sql = “SELECT _CATEGORY, _SUBCATEGORY FROM categories WHERE _DEPT = ‘$dept'”;

$db = new MysqliDb(‘CES’);

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

if ($selectStatus > 0) {

foreach ($selectStatus as $row) {

$categoryArray[] = $row[‘_CATEGORY’];
$subcategoryArray[] = $row[‘_SUBCATEGORY’]; 

}

}


 

PHPArrayToJSArray

$(document).ready( function () {

var subcategoryArray = <?php echo ‘[“‘ . implode(‘”, “‘, $subcategoryArray) . ‘”]’ ?>; 

 

On select

$(‘#_CATEGORY_LIST0’).on(‘select2:select’, function (e) {
$(‘#SUB_CATEGORY_LIST0’).val(subcategoryArray[e.params.data.id]);
});

Posted in DOM, HTML, Javascript

Accumulating data for charts.js / Dynamic tables

document.getElementById(“categorysummary”).innerHTML = “”;

var newTable = “<table border=’1′ width=’99%’>”;

newTable += “<tr><th width=150px><b>” + cat + “</b></th><th width=200px><b>” + sub + “</b></th><th width=20px><b>” + actual + “</b></th><th width=20px><b>” + max + “</b></th><th width=20px><b>” + weight + “</b></th></tr>”;

 

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

myLabelarray[i] = response[i]._SUBCATEGORY;

cattofive = response[i]._CATTOFIVE;
myActualarray[i] = response[i]._CATTOFIVE;

catpoints = response[i]._CATPOINTS;
myMaxarray[i] = response[i]._CATPOINTS;

cat = response[i]._CAT;

catcalc = (cattofive / catpoints) * cat / 1;
catcalctot = catcalctot + catcalc;

catcalctot = round(catcalctot, 2);

newTable += “<tr><td>” + response[i]._CATEGORY + “</td><td>” + response[i]._SUBCATEGORY + “</td><td align=’right’>” + response[i]._CATTOFIVE + “</td><td align=’right’>” + response[i]._CATPOINTS + “</td><td align=’right’>” + response[i]._CAT + “</td></tr>”;

$(“#_OVERALLPERCENTAGE”).val(response[i]._OVERALL);
$(“#_WEIGHTEDPERCENTAGE”).val(catcalctot);

}

newTable += “</table>”;

document.getElementById(“categorysummary”).innerHTML = newTable;
myChartjs (myLabelarray, myMaxarray, myActualarray);

$(“#chart1”).hide();
$(“#chart2”).hide();

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’);

}