Jump to content

A little help please.


Scip

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/163529-a-little-help-please/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.