Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8217967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:37:39+00:00 2026-06-07T12:37:39+00:00

Been at this for a long time, and it seems so simple but I

  • 0

Been at this for a long time, and it seems so simple but I cannot get it to do what I want.

Each book has a ‘getOrRequest’ value that is selected using radio buttons. Every time a div is duplicated, the name value needs to be changed so that a book has its own getOrRequest value. I’ve finally got the duplicating down, but now renaming the correct inputs isn’t cooperating.

What’s really bugging me is that it works, but it’s not changing the name values that I’m trying to grab. It has something to do with what parts of the array are being changed, but I can’t get the values that I want, namely the last two getOrRequest names.

A working example of what I’m struggling with here.

My JS function:

function addAnotherPost(){

var bookInfo = document.getElementById('bookInformation');
var copyDiv = document.getElementById('addListing').cloneNode(true);

copyDiv.id = 'addListing' + idNumber;
bookInfo.appendChild(copyDiv);

var divID = 'addListing' + idNumber;
var newDiv = document.getElementById(divID);
var postType = document.getElementsByName("getOrRequest[]");

alert(postType[0].name + postType[1].name + postType[2].name + postType[3].name);

for(var i = 2; i < postType.length; i++){
   postType[i].name = 'getOrRequest' + idNumber + '[]';
}

alert("got this far" + postType.length);

idNumber++;
}

The relevant chunk of HTML:

<div id='addListing'>
<table class='aListing'>
<tr>
<td>
                <label>
                <input type='radio' name='getOrRequest[]' value='1' />
                Request</label>
                <label>
                <input type='radio' name='getOrRequest[]' value='0' />
                Offer</label>
</td>
[...]
</table>
</div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T12:37:40+00:00Added an answer on June 7, 2026 at 12:37 pm

    You are getting an object list for a specific name identifier:

    var postType = document.getElementsByName("getOrRequest[]");
    

    so postType is changing once you’ve renamed an element (Yes man that thing is inteligent)

        console.log(postType.length); // = 4
        postType[i].name = 'getOrRequest' + idNumber + '[]';
        console.log(postType.length); // = 3
    

    so basically the for loops changes because postType.length changes.

    I guess what you want to do is something like:

    postType[0].name = 'getOrRequest' + idNumber + '[]'; //ref changed.
    postType[0].name = 'getOrRequest' + idNumber + '[]';
    

    however thats bad style anyways you should clone from a marked source and rename by name before you append to something, like so ( http://jsfiddle.net/bHLZA/2/ ):

    var bookInfo = document.getElementById('bookInformation');
    var copyDiv = document.getElementById('addListing').cloneNode(true);
    
    copyDiv.id = 'addListing' + idNumber;
    postType = copyDiv.getElementsByTagName('input');
    postType[0].name = 'getOrRequest' + idNumber + '[]';
    postType[1].name = 'getOrRequest' + idNumber + '[]';
    bookInfo.appendChild(copyDiv);
    

    see http://jsfiddle.net/bHLZA/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to solve this issue for a long time, and nothing seems
This has been pending for a long time in my list now. In brief
This problem has been bugging me for a long time. For example, the code
I've been stuck for a very, very long time on this issue, which has
.NET code access security has been around for a long time, yet it seems
I've been googling this for long time! I need to show images on some
I've been trying this from a long time. I'm having today's date and I
I've been using this script for a long time and it works perfectly in
I've been working on this for a long time now and can't figure out
Ive been tryin to solve this for a long time and now know why

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.