On #2. i tried it without the jquery and got the same type error: Uncaught TypeError: Cannot read property 'previousElementSibling' of undefined
<html>
<head>
<title>kcTst</title>
<script src="main.js"></script>
<script src="jquery-2.1.3.min.js"></script>
</head>
<body>
<div id='inputTst' >Code
<input type='text' id='BarCode' autofocus value="" />
</div>
<div class="imgbox" id="imgbox1">
<a href=# id='122' name='122' class="itmLink">
pic122</a><br>
</div>
<div class="imgbox" id="imgbox1">
<a href=# id='777' name='777' class="itmLink">
pic777</a><br>
</div>
<div id="itemList" class="lineItems">
<TABLE ID=CSHTBL>
<tbody id=ItmBody>
</TABLE>
</div>
</body>
</html>
js file:
window.onload = function() {
var x = document.querySelectorAll('.itmLink');
var i;
for (i = 0; i < x.length; i++){
x[i].addEventListener("click", linkClick);
}
};
// FINISHED ONLOAD FUNCTION ----------------------------
var Qty = 1;
function linkClick(){
document.querySelector('#BarCode').value =
this.id;
addItmDiv();
};
function addItmDiv() {
var x = document.getElementById("BarCode");
x.style.backgroundColor = 'red';
var ITM = x.value;
var namItm = "Itm" + ITM;
var namQ = "Nam" + Qty;
var pNode = document.getElementById("ItmBody");
var trNode = document.createElement('tr');
trNode.setAttribute("id", namItm);
trNode.setAttribute("class", "rmv");
trNode.innerHTML = "<td id='cbtn'><a href=#><img src='/trash.png' alt='X'></a></td>";
pNode.insertBefore(trNode, pNode.childNodes[0]);
var nmNode = document.createElement('td');
nmNode.setAttribute("id", namQ);
nmNode.setAttribute("class", "TiTl");
var txt = "<a href=#>" + namItm + "</a>";
nmNode.innerHTML = txt;
trNode.appendChild(nmNode);
var qtyNode = document.createElement('input');
qtyNode.setAttribute("id", "IQty");
qtyNode.setAttribute("value", "1");
trNode.appendChild(qtyNode);
var upNode = document.createElement('a');
upNode.setAttribute("id", "upQ");
upNode.setAttribute("class", "upbtn");
upNode.innerHTML = "+";
trNode.appendChild(upNode);
Qty += 1;
document.querySelector('.upbtn').addEventListener("click", upQTY);
}
function upQTY() {
var qty = parseInt($(this.activeElement.previousElementSibling).val());
qty += 1;
$(this.document.activeElement.previousElementSibling).val(qty);