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 957173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:39:31+00:00 2026-05-16T00:39:31+00:00

Ok, so what I am trying to achieve is, when the user clicks on

  • 0

Ok, so what I am trying to achieve is, when the user clicks on add, it will create a new instance of highway along with mallName and frequency, each of which will have a unique id, eg: highway1, mall1, freq1 : highway2, mall2, freq2
etc etc.

But thus far, when I click add, it adds the items, but when I click use the second drop down list that has been generated, or the third, or fourth etc etc, the first list reacts to it!

I am assuming that it is because I am failing to provide a unique ID to the functions that generate the drop down lists.

How can I fix this issue?

Here is the code that dynamically adds new form instances:

$(document).ready(function() {

     $('#btnAdd').click(function() {
            var num     = $('.clonedSection').length;
            var newNum  = new Number(num + 1);

            var newSection = $('#clonedSection' + num).clone().attr('id', 'clonedSection' + newNum);

            newSection.children(':first').children(':first').attr('id', 'mallName' + newNum).attr('name', 'mallName' + newNum);
            newSection.children(':nth-child(2)').children(':first').attr('id', 'frequency' + newNum).attr('name', 'frequency' + newNum);

            $('.clonedSection').last().append(newSection)

            $('#btnDel').attr('disabled','');

            if (newNum == 5)
                $('#btnAdd').attr('disabled','disabled');
        });

        $('#btnDel').click(function() {
            var num = $('.clonedSection').length; // how many "duplicatable" input fields we currently have
            $('#clonedSection' + num).remove();     // remove the last element

            // enable the "add" button
            $('#btnAdd').attr('disabled','');

            // if only one element remains, disable the "remove" button
            if (num-1 == 1)
                $('#btnDel').attr('disabled','disabled');
        });

        $('#btnDel').attr('disabled','disabled');
    });

</script>

Here is the code that generates the dynamic drop down lists:

    <script>
              centres = new Array();
  centres[0] = new Array( 'Brits Spar Centre', 'Safari Plaza', 'Shoprite Centre');
  centres[1] = new Array( 'Xanadu X-ing');
  centres[2] = new Array( 'CheckersHyper Centre', 'City Mall', 'Flamwood Walk Shopping Centre', 'Game Centre', 'Klerksdorp 01', 'MCC Superspar Centre', 'Pick n Pay Hypermarket', 'Songloed Shopping Centre', 'The Terminus');

  centres2 = new Array();
  centres2[0] = new Array( 'BLA Brits Spar Centre', 'Safari Plaza', 'Shoprite Centre');
  centres2[1] = new Array( 'BLA Xanadu X-ing');
  centres2[2] = new Array( 'BLA CheckersHyper Centre', 'City Mall', 'Flamwood Walk Shopping Centre', 'Game Centre', 'Klerksdorp 01', 'MCC Superspar Centre', 'Pick n Pay Hypermarket', 'Songloed Shopping Centre', 'The Terminus');
  centres2[3] = new Array( 'BLA Lichtenburg Centre');

  cities1 = new Array( 'Brits', 'Klerksdorp', 'Lichtenburg', 'Mabopane', 'Mafikeng', 'Marikana', 'Mmabatho', 'Mogwase', 'Orkney', 'Phokeng', 'Potchesfstroom', 'Rustenburg', 'Sun City', 'Taung', 'Temba', 'Vryburg');
  cities2 = new Array( 'pew', 'pong', 'wong', 'Mabopane', 'Mafikeng', 'Marikana', 'Mmabatho', 'Mogwase', 'Orkney', 'Phokeng', 'Potchesfstroom', 'Rustenburg', 'Sun City', 'Taung', 'Temba', 'Vryburg');



function showHide(obj){
 var curSel = obj.options[obj.selectedIndex].value;

 switch(curSel)
 {
 case 'Free State':

  populateDropDown2(cities1, curSel);
  currentArray = '0';

   break;
 case 'Gauteng':

  populateDropDown2(cities2, curSel);
  currentArray = '1';

   break;
 case 'KZN':
   break;
 case 'Limpopo':
   break;
 case 'Mpumalanga':
   break;
 case 'North West':
   break;
 case 'Northern Cape':
   break;
 case 'Western Cape':
   break;
 default:
  $('#model').css({'display' : 'none'});
 }
}

function populateDropDown2(myArray, currentIndex)
{
   var x;
  $('#model').css({'display' : 'block'});

  $('#model').html("<select name='model' id='sub' onchange='showHideTwo(this);'>");
  for (var j=0; j<myArray.length; j++)
  {
   //populate the select with options
   $('#sub').append("<option value='" + j + "'>" + myArray[j] + "</option>");
  }  
}

function populateMalls(myNextArray, myNextIndex)
{
   var x;
  $('#browny').css({'display' : 'block'});

  $('#browny').html("<select name='browny' id='pie'>");
  for (var i=0; i<myNextArray[myNextIndex].length; i++)
  {
   //populate the select with options
   $('#pie').append("<option value='" + myNextArray[myNextIndex][i] + "'>" + myNextArray[myNextIndex][i] + "</option>");
  }  

}

function showHideTwo(obj) {
 var curSel = obj.options[obj.selectedIndex].value;


 switch(currentArray)
 {
 case '0':
  populateMalls(centres, curSel);
  $('#model').css({'display' : 'block'});

   break;
 case '1':
  populateMalls(centres2, curSel);
     break;

 default :

   break;

 }

}

            </script>

Any help would be greatly appreciated! thanx!

Also, the code might have a few syntax errors in since I have been working on it a while and I might have missed a few small things, so apologies in advance!

  • 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-05-16T00:39:31+00:00Added an answer on May 16, 2026 at 12:39 am

    Looking at this…

    //populate the select with options
    $('#sub').append("<option value='" + j + "'>" + myArray[j] + "</option>");
    

    my guess is that you need id=”sub1″, id=”sub2″ etc. for the sections you add. You didn’t include your HTML, but it seems that the elements in each section have the same ids.

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

Sidebar

Related Questions

This is what I am ultimately trying to achieve: //When the user clicks the
I am trying to achieve a modal overlay using jQuery. When a user clicks
I'm trying to achieve two things, both of which I fail to get at.
In my application, when the user clicks an infoButton, it should add another view
I am trying to make it so that when a user clicks something on
I'm trying to add a new entry into Internet Explorer's right-click context menu. I
I am trying to stop a file from uploading when the user clicks on
Trying to achieve any moving effect while appending an element from one to another
im trying to achieve something but i dont really know how I have set
I am trying to achieve reading variables from a Java applet out of process

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.