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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:31:45+00:00 2026-05-27T08:31:45+00:00

I have a project that merges in one form field two variables. Number of

  • 0

I have a project that merges in one form field two variables.

  1. Number of rooms
  2. Number of persons per room.

This only field will have the value each room/persons per room and each room will be delimited by “|”.

So you have 3 rooms and 2 persons in each room = 2|2|2

Or 2 rooms, 1st room 2 persons and 2nd room 3 persons = 2|3

I have ready two jQuery functions:

  1. A cloning of the # of persons and
  2. The update of the values of the cloned items.

The problem I have is that each function works independently and when the users update one the single form field dos not update.

How can merge or update the two functions that work as one?

I have posted a working example @

http://jsfiddle.net/HxsnJ/

Here is the HTML code

Number of rooms<br />
<select id="itemCount" name="itemCount">
 <option selected value="1">1 item</option>
 <option value="2">2 items</option>
 <option value="3">3 items</option>
 <option value="4">4 items</option>
</select><br /><br />
Number of persons<br />
<select name="cloneElement1" id="item_dup_1" class="room">
  <option value="">Select One</option>
  <option value="1">1</option>
  <option selected value="2">2</option>
  <option value="3">3</option>
</select><br /><br />

<input type="text" name="myNumbers" value="2"> 

And here the jQuery

    // fn Clone Boxes
jQuery.fn.fieldsManage = function (number) {
    var ele = $(this);
    var clones = ele.data("clones");
    clones = clones ? clones : new Array(ele.attr("id"));
    if (clones.length < number) {
        var clone;
        while(clones.length < number) {
            clone = ele.clone(true);
            var id = clones[0]+clones.length;
            clone.attr("id", id);
            $("#"+clones[clones.length-1]).after(clone);
            clones.push(id);
        }
    } else {
        while(clones.length > number) {
            $("#"+clones.pop()).remove();
            $(function(){
                $("[name='myNumbers']").val(myNumbers.join('|'));
            });
        }
    }
    ele.data("clones", clones);
}
// Create Clone Boxes
$(document).ready(function() {
    $("#itemCount").change(function() {
        $("#item_dup_1").fieldsManage(this.value);
    });
});

// Values from Cloned Boxes
$(function(){
    $('.room').change(function(e){
        var myNumbers = [];
        $('.room').each(function(){
          myNumbers.push($(this).val());
        })
        $("[name='myNumbers']").val(myNumbers.join('|'));
    });
});
  • 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-27T08:31:46+00:00Added an answer on May 27, 2026 at 8:31 am

    Is your problem that the value is not refreshing when you select a different number of rooms? If so take a look at this http://jsfiddle.net/gSkpq/

    Note you can use jQuery’s live to bind an event to elements that might be dynamically added and removed

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

Sidebar

Related Questions

I have an object Project which has a number of fields, one of which
Some of my .csproj project files have special target AssembleJS that merges all .js
I have an Android project(A) that uses one library module(B) in Intellij IDEA 11.
I have some general purpose classes in one project that I would like to
I have project that I'm working on that is going to require a webserver.
I have a project that I'm currently working on but it currently only supports
I have a project that I would like to start beta testing soon, it
I have a project that I'm working on and I need to be able
We have a project that generates a code snippet that can be used on
I have a project that I thought was going to be relatively easy, but

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.