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

  • Home
  • SEARCH
  • 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 8953749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:10:05+00:00 2026-06-15T14:10:05+00:00

I want change name attribute in <input> element, I have in the here several

  • 0

I want change name attribute in <input> element, I have in the here several name string[0][], now i want after click on link add change ‍‍0 in they and replace 1 instead all 0. How is it by Jquery?

DEMO: http://jsfiddle.net/2hXk5/

I try as but don’t work for me:

<div class="ch">
    <p>
        <input type="checkbox" name="cDA[0][]">
        <input type="checkbox" name="cDA[0][]">
        <input type="checkbox" name="cDA[0][]">
        <input type="checkbox" name="cDA[0][]">
    </p>
    <p>
        <input type="checkbox" name="cFE[0][]">
        <input type="checkbox" name="cFE[0][]">
        <input type="checkbox" name="cFE[0][]">
        <input type="checkbox" name="cFE[0][]">
    </p>
    <p>
        <input type="checkbox" name="cYG[0][]">
        <input type="checkbox" name="cYG[0][]">
        <input type="checkbox" name="cYG[0][]">
        <input type="checkbox" name="cYG[0][]">
    </p>
    <a href="" class="adding">Add</a>
</div>
​


$('a.adding').live('click change', function (e) {
    e.preventDefault();
    $clone = $(this).closest('.ch').clone().insertAfter('.ch');
    $clone.find('input[type="checkbox"]:contains("0")').prop('1');
})​
  • 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-15T14:10:07+00:00Added an answer on June 15, 2026 at 2:10 pm

    If I understand you correctly, you want to use .attr() with a callback function:

    $('input[type="checkbox"]').attr('name',function(i,str) {
        return str.replace('0','1');
    });
    

    UPDATE: Here’s a complete version which will do everything you seem to actually want. It uses str.match(/\d+/) to extract the FIRST number-string in the name attribute, converts it to an integer, then replaces it with the next integer using str.replace. Note the insertAfter part was updated so it only inserts after the LAST div.ch:

    $(document).on('click change', 'a.adding', function(e) {
        e.preventDefault();
        $div = $(this).closest('.ch');
        $clone = $div.clone().insertAfter($div);
        $clone.find('input[type="checkbox"]').attr('name', function(i, str) {
            var int = parseInt(str.match(/\d+/)[0],10);
            return str.replace(int, (int+1));
        });
    });​
    

    http://jsfiddle.net/mblase75/3SGNw/

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

Sidebar

Related Questions

I have an ImageButton which I want to change the NAME attribute of in
I have style sheet with a class name changebackgroundcolor i want make change in
I have a table of input fields where I want to 1)change the first
I want to change an attribute of a checkbox tag after the success of
Suppose I have this XML document... <root> <str name=My node's attribute>My string's value</str> </root>
I want to change the value under key by matching the name attribute for
I want to change the name of enter button (the button circled in the
I want to change the name of the uploaded file, to the current time
I have a RadioButtnList. I want change body background color based on radio button
i have many div's with the same background image and i want change this

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.