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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:58:16+00:00 2026-06-07T14:58:16+00:00

I have a button each time it is clicked, a new select input will

  • 0

I have a button each time it is clicked, a new select input will be added. But I want the id and name of the select changed as well.My codes was:

<section>
  <div class="container">
   <select id="myId_1" name="myName_1">
     <option value="1">1</option>
     <option value="2">2</option>
   </select>
  </div>
</section>
<button type="button" id="myBtn">add</button>

$(document).ready(function () {
    $('#myBtn').click(function(){
      var addEvent = $('.container').html();
      var addEventCell = $('<div class="container">'+addEvent+'</div>');
      $('section').append(addEventCell);
    });
  });

But my code just duplicates the id and name of select. I want it to change to myId_2, myName_2,myId_3,myName_3 and so on.

I am new to javascript. It could be easy to you guys. Thanks for help !

  • 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-07T14:58:18+00:00Added an answer on June 7, 2026 at 2:58 pm

    this is the link for JSFiddle working here. It may be useful for you

    $(document).ready(function () {
        $('#myBtn').click(function(){
          var addEvent = $('.container').html();
    
          var selectid = $('section :last-child select').attr('id'); 
          var selectname = $('section :last-child select').attr('name'); 
    
          var tempId = parseInt(selectid.split('_')[1])+1; 
          var tempName = parseInt(selectname.split('_')[1])+1; 
          var addEventCell = $('<div class="container">'+addEvent+'</div>');
    
          var newId =  selectid.split('_')[0]+"_"+tempId; 
          var newName = selectname.split('_')[0]+"_"+tempName ;
    
          var select = $('select', addEventCell);
          select.attr('id', newId).attr('name', newName);      
    
          $('section').append(addEventCell);
        });
      });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say, I want to open up a new thread each time a button is
i have application with Listbox and files, each time i press on Add button
I have few buttons of which each button is assigned a class with a
I have a big table containing a button in each cell. These buttons are
I have some 10 buttons with different names each.On selecting each button I need
I have 4 buttons on a page. Each button opens a modal window and
I have butons which are created dynamically, each button has an id set in
I have 3 buttons with same ID. I need to get each button's value
I have a lot of buttons on main activity. Each button run this same
I have a custom UITableViewCell which contains several UIButtons. Each button's frame position is

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.