I've had a hard time getting dynamic rows inputs to multiply 'onchange' of the value in the input in each row. It works in the first row inserted no matter what rowindex that row is moved to. All following rows only accept the initial input value and never change the 'cost' innerHTML of the colRow. I figure I need a parentNode.parentNode syntax to make this function work in all rows. Every thing is Client-side javascript and all rows are inserted to 'cartbody.insertRow[0]'.

'qtymultiply()' Function As is:

function qtymultiply(){
var cartitems=document.getElementsByClassName('itemrow');
var colRows=cartitems;
for(var i=0; i < colRows.length; i++)
{
var oRow=colRows[i];
var price=oRow.cells[4].innerHTML;
var qty=oRow.cells[5].getElementsByTagName('input')[0].value; 
var cost=oRow.cells[6]; //not recognized for each row only first row- //inserted
var multiply=0.0;
multiply+=price*qty;
}
cost.innerHTML=multiply.toFixed(2); //need the 'cost' of each row to-
//change not just the first row inserted?
sumsubtotal(); //re-adds 'subtotal'
}

Any suggestions for a parentNode syntax on the 'itemrow' would be greatly appreciated.

This alert verifies that oRow isn't colRows[i]

'qtymultiply()' Function With Alert:

function qtymultiply(){
var cartitems=document.getElementsByClassName('itemrow');
var colRows=cartitems;
for(var i=0; i < colRows.length; i++)
{
var oRow=colRows[i];
var price=oRow.cells[4].innerHTML;
var qty=oRow.cells[5].getElementsByTagName('input')[0].value; 
var cost=oRow.cells[6]; [COLOR="Red"]//not recognized for each row only first row- //inserted[/COLOR]
var multiply=0.0;
multiply+=price*qty;
}
cost.innerHTML=multiply.toFixed(2); [COLOR="Red"]//need the 'cost' of each row to-
//change not just the first row inserted?[/COLOR]
sumsubtotal(); [COLOR="Red"]//re-adds 'subtotal'[/COLOR]
alert(oRow.innerHTML); [COLOR="Red"]//returns first row inserted only[/COLOR]
}

Any suggestions for a parentNode syntax on the 'itemrow' would be greatly appreciated.

This Alert adds each rows innerHTML to the Alert dialog every time the input onchange is called.
'qtymultiply()' Function With Alert:

function qtymultiply(){
var cartitems=document.getElementsByClassName('itemrow');
var colRows=cartitems;
for(var i=0; i < colRows.length; i++){
var oRow=colRows[i];
var price=oRow.cells[4].innerHTML;
var qty=oRow.cells[5].getElementsByTagName('input')[0].value; 
var cost=oRow.cells[6]; //not recognized for each row only first row- //inserted
var multiply=0.0;multiply+=price*qty;
}
cost.innerHTML=multiply.toFixed(2); //need the 'cost' of each row to-//change not just the first row inserted?
sumsubtotal(); //re adds 'subtotal'
alert(cost.parentNode.parentNode.innerHTML); //writes all new rows innerHTML to alert dialog box
}

Any suggestions for a parentNode syntax on the 'itemrow' would be greatly appreciated.:-O

I resolved this issue Myself
Add row in 'display' window 'Product.html' external js.

//relavent part
var addquantity=itemrow.insertCell(5);
addquantity.className='quantity';
addquantity.innerHTML='<input type="text" value="'+quantity+'" title="You may change the quantity of this item" name="qty[]" class="qty" onkeydown="itemrowMultiply(this.value);" />';

'itemrowMultiply()' in 'register' window 'Checkout.html ext. js

//relevant part
function itemrowMultiply() {
var aObj=document.getElementsByClassName('qty');
for(var i=0; i<aObj.length; i++) {
    aObj[i].onchange=function() {qtymultiply(this);};
    }
};

function qtymultiply(qty){
var fs=qty.parentNode.parentNode;
var subtotal=document.getElementById('subtotal');
var args=[0,1,2,4,6,8,10,20];
var multiply=0.0;
var price=fs.cells[4].innerHTML;
var quantity=fs.cells[5].getElementsByTagName('input')[0].value; 
var cost=fs.cells[6];
var rowsubtotal=fs.cells[7];
if(qty.value!=''||qty.value!=0||qty.value.isNaN){
//need if qty.value dosen't match(args) to cause alert
multiply+=price*quantity;
cost.innerHTML=parseFloat(multiply).toFixed(2);
sumsubtotal();
rowsubtotal.innerHTML=subtotal.innerHTML;
}
else {
alert('You only have these options: 1,2,4,6,8,10 or 20');
qty.focus;
}
}

This works but I'd like to get the alert to run when the new value entered in the inputs dose not match the elements in 'args' array. Any help would be greatly appreciated.:-/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.