Scip Posted June 24, 2009 Share Posted June 24, 2009 Having some problems with this javascript code i am trying to write. I am trying to clone a row at the click of a button, edit the row to remove stuff and give new attributes to the input tag. Then insert the edit row into a new table. A bit like an online shopping cart. The problem is i am getting an error that pickButton.firstChild is null, i can't figure out what wrong, then again i am very new to javascript and my skills are basic at best. Here is the HTML. <tr class="row"> <td>image.gif</td> <td>Bowl</td> <td>200</td> <td><input type="button" name="" value="Add" onclick="lootBasket(this)"/></td> here is the javascript. function lootBasket(obj){ var parentRow = obj.parentNode.parentNode; var clonedParent = parentRow.cloneNode(true); var image = clonedParent.firstChild; clonedParent.removeChild(image); var pickButton = clonedParent.lastChild; var pickButtonVal = pickButton.firstChild.getAttributeNode("value"); pickButtonVal.value="Remove"; pickButton.firstChild.getAttributeNode("onclick","remove(this)"); var cartTable = document.getElementById('cart-table'); cartTable.appendChild(clonedParent); Quote Link to comment Share on other sites More sharing options...
Scip Posted June 25, 2009 Author Share Posted June 25, 2009 Anyone? Heck if my code is complete nonsense you could at least tell me. Quote Link to comment Share on other sites More sharing options...
dzelenika Posted June 25, 2009 Share Posted June 25, 2009 Try to debug variables parentRow clonedparent and image using alert js command. I'm not sure than they are what you expecting. If you are using Firefox install extension Firebug to debug Javascript. This extension is great help in js developing. Quote Link to comment Share on other sites More sharing options...
Scip Posted June 25, 2009 Author Share Posted June 25, 2009 Thanks i will give firebug a go. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.