title: Changing radio buttons name using Javascript
body: <p>I'm using a simple JS duplicate function to duplicate a div. Inside is form information with radio buttons, including one group called 'getOrRequest'. Each div represents a book and needs to have its own 'getOrRequest' value. </p>
  
  <p>The name needs to be changed in order to make each duplicated group of radio buttons selectable without affecting every other radio button. What is the best way to change these values?</p>
  
  <p>Here is how I'm duplicating the div, in case that is the issue.</p>
  
  <pre><code>var bookInfo = document.getElementById('bookInformation');
  var copyDiv = document.getElementById('addListing').cloneNode(true);
  bookInfo.appendChild(copyDiv);
  </code></pre>
  
  <p>I then have tried a couple methods of changing the name value. Like this:</p>
  
  <pre><code>bookInfo.copyDiv.getOrRequest_0.setAttribute("name", "'getOrRequest' + idNumber + '[]'");
  bookInfo.copyDiv.getOrRequest_1.setAttribute("name", "'getOrRequest' + idNumber + '[]'");
  </code></pre>
  
  <p>As well as this:</p>
  
  <pre><code>bookInfo.copyDiv.getOrRequest_0.name = 'getOrRequest' + idNumber + '[]';
  bookInfo.copyDiv.getOrRequest_1.name = 'getOrRequest' + idNumber + '[]';
  </code></pre>
  
  <p>getOrRequest_0 and getOrRequest_1 are the ID's of the input values, but I've tried it a few ways now and nothing seems to work. Thanks in advance!</p>
  
  <p>EDIT: MORE INFO</p>
  
  <p>Here is the specific code I'm using:</p>
  
  <pre><code>function addAnotherPost(){
  
  var bookInfo = document.getElementById('bookInformation');
  var copyDiv = document.getElementById('addListing').cloneNode(true);
  var size = copyDiv.childNodes.length;
  
  copyDiv.id = 'addListing' + idNumber;
  
  for(var j = 0; j &lt; size; j++){
     if(copyDiv.childNodes[j].name === "getOrRequest[]"){
        copyDiv.childNodes[j].name = "getOrRequest" + idNumber + "[]";
     }
  }
  
  bookInfo.appendChild(copyDiv);
  
  idNumber++;
  }
  </code></pre>
  
  <p>And it just doesn't seem to work.. The divs are duplicating, but the name value is not changing.</p>