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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:32:17+00:00 2026-06-11T07:32:17+00:00

Well i am trying to do a dynamic combo select inside a partial. and

  • 0

Well i am trying to do a dynamic combo select inside a partial. and the value of the batch no stays the same, ie whatever batch no i select in first partial rest of the partial has the same value.

Code is as follows

Form

<%= nested_form_for(@bill) do |f| %>

    <%= f.label :name %><br />
    <%= f.text_field :name %>
  <%= f.link_to_add "add product", :bill_line_items %>
    <%= f.submit %>
<% end %>

the partial

<%= javascript_include_tag 'testing' %>
  <div class ="kool">

  <div class ="name"><%= f.label :product_id %>
<%= f.collection_select :product_id,Product.all ,:id,:name, :style => 'width:150px;'%></div><br />

    <div class="list">
    <%= f.label :batch_no %><br />
    <%= f.grouped_collection_select :batch_no, Product.all, :store_opening_stocks, :id, :batch_no, :batch_no %><br/></div>

  </div>

Js File

    jQuery(document).ready(function(){
       var batchNo = jQuery('.list').html();

  jQuery('.name').bind('change',function() {

     var  productSelected = jQuery('.name:selected').val();

   var options = jQuery(batchNo).find("optgroup[label='" + productSelected + "']").html();

     jQuery('.list select').html(options);

            });
          });

Screen Shots before selecting product

before Selecting the product

Screen Shot After selecting product and clicking on Add product

after selecting product and clicking add product

Screen shot after Reselecting product again

Reselecting product again

as you can see the Product-2 group i’e P1 and P2(batch nos of product 2) coming in second and third partial. and any attempt to change product, the batch nos show empty as shown in the picture.

how do i solve this problem?? should i use Parent somewhere or this option?? Guidance required.

Thanks in advance. 🙂

  • 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-11T07:32:19+00:00Added an answer on June 11, 2026 at 7:32 am

    Try this. it will help. use the parent element to get the value of that particular form. in this case parent is kool and getJSON method is better prefered than this method so your code will be something like this.

    jQuery(document).ready(function()
    {
    jQuery(".prod select").bind("change", function() {
          var data = {
            product_id: jQuery(this).val()  
          }
          var wrapperDivElement = jQuery(this).parents(".kool");
          jQuery.getJSON(
             "/customer_bills/get_batch",
            data,
            function(data){
          var result = "",a;
          var b = "<option>Select Batch no</option>"
          for(i=0;i<data.length; i++)
          {
           a = data[i];  
           result = result + "<option value="+a[0]+">"+a[0]+"</option>";
          }
           jQuery('.batch select', wrapperDivElement).html(b+result);
          });            
            });
        }); 
    

    in controller

    def get_batch
        @product_batch = StoreOpeningStock.find_all_by_product_id(params[:product_id]).map{|p| [p.batch_no, p.price]} if params[:product_id]
        respond_to do |format|
          format.json { render json: @product_batch }
        end
      end
    

    and in routes

    resources :customer_bills do
        collection do
          get :get_batch
        end
      end
    

    this method is much more clear and better. all the best 🙂

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

Sidebar

Related Questions

I'm trying to load the dynamic content of a page as well as the
I am trying to create a screen with some dynamic controls, well radio buttons
I'm creating a dynamic combo box and adding to a form. I'm trying to
Well im trying to write my own custom control extender but i can't get
well iam trying to get version of IE used by user by using $.browser.version
Hi guys thanks for pay attention to this. Well im trying to replace every
Well,I am trying to do something similar what I did in Adobe Flex.Consuming a
Well I'm trying to set a variable to use in a thread, it works
Well I am trying to learn the java MVC pattern, but I can't understand
Alright well I am trying to create a dictionary from a text file so

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.