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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.