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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:36:34+00:00 2026-05-25T13:36:34+00:00

I have a form that asks for addresses. After each address, we ask how

  • 0

I have a form that asks for addresses. After each address, we ask how long the person has lived in that address, with <select> dropdowns for Years and Months.

I have a jQuery event each time the <select> is changed:

var prev_addresses = 0;
$('select.months, select.years').change(function() {

    // Calculate total months
    var months = $('select.months').val();
    var years = $('select.years').val();
    var total_months = parseInt(months) + parseInt(years*12);   // We parseInt() to avoid concatenation

    console.log('Total months: '+total_months);

    if(total_months < 12) {
        // Find the next div.hidden-address
        prev_addresses = prev_addresses+1;
        console.log('Number of previous addresses: '+prev_addresses);
        console.log('');
        $('div.hidden-address').clone(true).appendTo('#previous-addresses').slideToggle();
    }
});

I want this to keep on happening all the while a person has less than 12 months of addresses. However after the first time the event fires, every time a <select> is updated the console just logs the first set of values (from the original Year and Month selects, even though there are now multiple ones).

I want to total up the values of every <select> element on a page, even after more are added dynamically. How can I do this?

Hope that makes sense, I’m happy to clarify if you need further details.

Thanks,

Jack

  • 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-25T13:36:34+00:00Added an answer on May 25, 2026 at 1:36 pm

    Loop through all select boxes, and add the value to a variable, something like this:

    var totalMonths = 0;
    $('select.months').each(function () {
        totalMonths += $(this).val();
    });
    
    $('select.years').each(function () {
        totalMonths += 12 * $(this).val();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php page that has a form that asks for an e-mail.
I have a form that asks for a email and city. The city select
I currently have form that checks if a user has unsubmitted changes when they
I have a form that has multiple fields, and for testing purposes is there
I have a form that asks users to input numbers into multiple form fields.
I have a form that asks users to enter a start and end time
I have an assignment that asks me to retrieve delimited text from form values.
At http://localhost/tmp/ I have a form that asks for the user and password (authentication).
I have an input field that asks for an email address followed by a
In my Rails 3 app, I have a form that asks users to write

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.