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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:48:08+00:00 2026-06-12T10:48:08+00:00

Please consider the following javascript and html below. When addAnotherAddress() is run the first

  • 0

Please consider the following javascript and html below.
When addAnotherAddress() is run the first time, I’m expecting that all of the 1’s inside <div class="previous_address1"> will be replaced with 2’s and then that html will be appended to <div id="previous_addresses"> but that’s not happening when html.replace(pattern, current_address + 1) runs.

What am I doing wrong here?

Javascript

var current_address = 1; // Used when adding in previous address entries

function addAnotherAddress() {
    var pattern = '/' + current_address + '/g';
    var html = $('.previous_address' + current_address).html();

    html = html.replace(pattern, current_address + 1);

    $('#previous_addresses').append(
        '<div class="previous_address' + (current_address + 1) + '">' + html + '</div>' 
    );
    current_address += 1;
}

Html

<div id="previous_addresses">
    <span class="text_line">
    <u>Previous Addresses for Past 5 Years</u>
    </span>
    <div class="previous_address1">
    <span class="text_line">
        <i>Address 1</i>
    </span>
    <span class="text_line">
        <label for="previous_street1">Street:</label>
        <input type="text" id="previous_street1" />
    </span>
    <span class="text_line">
        <label for="previous_city1">City:</label>
        <input type="text" id="previous_city1" />
    </span>
    <span class="text_line">
        <label for="previous_state1">State:</label>
        <input type="text" id="previous_state1" />
    </span>
    <span class="text_line">
        <label for="previous_zip1">Zip:</label>
        <input type="text" id="previous_zip1" />
    </span>
    <span class="text_line">
        <label for="previous_county1">County:</label>
        <input type="text" id="previous_county1" />
    </span>
    </div>
</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-12T10:48:09+00:00Added an answer on June 12, 2026 at 10:48 am

    You can not use directly a regexp pattern in a string format, you have to evaluate it :

    html = html.replace(new RegExp(current_address, "g"), current_address + 1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please consider the following scenario with a simple HTML document and a JavaScript loaded
please consider the following javascript code: myObject.myMethod();.replace(/\.\w+\(/g, xxx); it gives myObjectxxx); as .myMethod( is
Consider the following example code: http://code.google.com/apis/maps/documentation/javascript/examples/streetview-simple.html I can do scrollwheel: false on a mapOptions
I have an app that's about presenting fictional simplified cities. Please consider the following
Please consider following example: The source image consists of 6 areas that need to
Please consider the following view: <p>Count <span data-bind=text: unreadCount()>&nbsp;</span></p> <div data-bind='template: { name: conversationTemplate,
Consider the following example : HTML: <div class=wrapper> <div class=left>Some text here</div><div class=right>Hello Stack
Please consider following snippet: <div class=row> <div class=span12> <div class=control-group> <label class=control-label>Person Name</label> <div
Please consider the following XML-- <div id=test> <p> Text sihdfaif</p> <p /> <p> Text
Please consider the following: <td style=width: 500px;> <div style=width: 400px;>SomeContent</div> </td> For some reason,

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.