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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:09:58+00:00 2026-06-05T08:09:58+00:00

I have a html page where i have a few textfields. Each set of

  • 0

I have a html page where i have a few textfields. Each set of textfields belongs inside a DIV. I want to change the name of certain textfields. But perhaps this gets more clear when you take a look at the example html:

http://jsfiddle.net/dg2Bz/

As you can see the first div has 3 text elements with this as name:

test[something][xxxx]

But the other “dummy” divs have textfields with a number:

<input name="test[100][name]" value="display" />
<input name="test[100][option1]" value="op1" />
<input name="test[100][option2]" value="op2" />

and

<input name="test[101][name]" value="borders" />
<input name="test[101][option1]" value="op1" />
<input name="test[101][option2]" value="op2" />

These fields all belong in a div. What i want to do is change the number part of the name and replace that with the value of the first textfield which has “name” in the “name” attribute. So that it becomes this:

<input name="test[display][name]" value="display" />
<input name="test[display][option1]" value="op1" />
<input name="test[display][option2]" value="op2" />

and

<input name="test[borders][name]" value="borders" />
<input name="test[borders][option1]" value="op1" />
<input name="test[borders][option2]" value="op2" />

I’m not sure how i could actually do this with jQuery. I’m sure it’s possible somehow and it probably involves some regex. Just can’t get my head around it…

  • 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-05T08:09:59+00:00Added an answer on June 5, 2026 at 8:09 am

    This is one possible solution:

    $(".dummy :input[name^=test]")​​​​​​​​​​​​​.attr("name", ​​function(i, value) {
        var name = $(this).parent().children(":first").val();
        return value.replace(/\[\d{3}\]/, "[" + name + "]");
    });​
    

    DEMO: http://jsfiddle.net/dg2Bz/1/

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

Sidebar

Related Questions

My html page loads beautifully, but I have some JavaScript that adds a few
I have a few html image tags that fill an array. On the page
I have a master page which containing few CSS links and java scripts. <html
I have HTML page of few tables created by ASP.NET and when I do
I have a section of an html page that I want to display in
I am using jQuery Mobile and have few pages in one HTML page. When
I have a HTML page that displays a few values. I also have a
I have the following HTML page: <div id=foobar> <?php echo $dynamicVar; ?> </div> <input
I have a few object params in HTML page I like to enumerate, what
I have few element in my html page which has tabIndex attribute. Now I

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.