hAnDoFhOnOr Posted February 17, 2006 Share Posted February 17, 2006 I need to get the name of document.getElementBy(app_table).cells(1).so the appliance in b.innerhtml , this changes everytime but if i reference the row i can get it i just can't get the right syntax. i know it's a long code but anyhelp would be appreciated. function addRow(classification, appliance, quantity, origquantity, costpermonth, wattage, hoursused, daysused, weeksused, row){ var app_table = 'table_' + classification; var x=document.getElementById(app_table).insertRow(row); var a=x.insertCell(0); var b=x.insertCell(1); var c=x.insertCell(2); a.innerHTML = '<input type="text" maxlength="2" class="formtext5" name="' + classification + '_quantity' + (document.getElementById(app_table).rows.length - 1) + '" value="' + quantity + '" onchange="java script:if(checkNum(this.value, "Appliance Quantity")){this.focus();this.value=this.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.value;}else{checkRemaining(Number(this.value-this.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.value)*Number(this.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.value), Number(document.energy.remaining.value));editQuantity(this.parentNode.parentNode.parentNode.parentNode.id, this.parentNode.parentNode.rowIndex);this.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.value=this.value;updateCES();if(this.parentNode.parentNode.parentNode.parentNode.rows.length>2){verifyPos(this.parentNode.parentNode.parentNode.parentNode.id, this.parentNode.parentNode.rowIndex);}}"><input type="hidden" name="' + classification + '_wattage' + (document.getElementById(app_table).rows.length - 1) + '" value="' + wattage + '"><input type="hidden" name="' + classification + '_hoursused' + (document.getElementById(app_table).rows.length - 1) + '" value="' + hoursused + '"><input type="hidden" name="' + classification + '_daysused' + (document.getElementById(app_table).rows.length - 1) + '" value="' + daysused + '"><input type="hidden" name="' + classification + '_weeksused' + (document.getElementById(app_table).rows.length - 1) + '" value="' + weeksused + '"><input type="hidden" name="' + classification + '_origquantity' + (document.getElementById(app_table).rows.length - 1) + '" value="' + origquantity + '"><input type="hidden" name="' + classification + '_costpermonth' + (document.getElementById(app_table).rows.length - 1) + '" value="' + costpermonth + '">'; b.innerHTML = appliance; c.innerHTML = '<nobr><input type=<input type="text" class="formtext6" name="' + classification + '_amount' + (document.getElementById(app_table).rows.length - 1) + '" value="' + round(Number(quantity)*Number(costpermonth), 2) + '" onfocus="this.blur();"> <input type="image" src="images/b-x.gif" name="' + classification + '_delete' + (document.getElementById(app_table).rows.length - 1) + '" id="' + classification + '_delete' + (document.getElementById(app_table).rows.length - 1) + '" width="8" height="9" border="0" alt="Remove appliance" onclick="removeRow(this.parentNode.parentNode.parentNode.parentNode.parentNode.id, this.parentNode.parentNode.parentNode.rowIndex);"> <input type="image" src="images/b-check.gif" name="' + classification + '_edit' + (document.getElementById(app_table).rows.length - 1) + '" id="' + classification + '_edit' + (document.getElementById(app_table).rows.length - 1) + '" width="12" height="10" border="0" alt="Edit appliance" onclick="this.parentNode.parentNode.parentNode.className=\'tdcon4\';editAppliance(this.parentNode.parentNode.parentNode.parentNode.parentNode.id, this.parentNode.parentNode.parentNode.rowIndex);"></nobr>'; var y=document.getElementById(app_table).rows; y[row].className = "tdcon3"; y[row].firstChild.nextSibling.nextSibling.className = "tdcon2";}function removeRow(app_table, i){ document.getElementById(app_table).deleteRow(i); if (applianceCount()<=0){ document.energy.remaining.value=""; document.energy.total.value=""; resetPie(); } else { updateCES(); }} Link to comment Share on other sites More sharing options...
Webworldx Posted February 28, 2006 Share Posted February 28, 2006 document.getElementById(app_table).getElementsByTagName('TD')[0] ??If you post the full code i'll be able to help you a bit more, but things like:this.parentNode.parentNode.parentNode.parentNode.rows.lengthdon't look too healthy! Link to comment Share on other sites More sharing options...
Pollux Posted February 28, 2006 Share Posted February 28, 2006 I haven't read through your code there in too much detail, but as Blue says, your referencing doesn't look too pretty! Would be a nightmare to debug. You should probably try to refactor it; look for a simpler way of achieving the same thing. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now