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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:31:07+00:00 2026-06-14T09:31:07+00:00

In my form I have two divs (bench_stock_items and non_bench_stock_items) with same fields with

  • 0

In my form I have two divs (bench_stock_items and non_bench_stock_items) with same fields with same ids. Using jQuery I disable one and enable other depending upon the value selected in client_id select which is not part of divs. I have a function that shows/hides different forms based on values selected in media_id select which is part of divs. My function works only for the select in first div which is loaded as enabled and not for the second div that is loaded disabled. I have tried almost everything. I am able to find the element:enabled properly in first div but not in second div.

Javascript:

<script type="text/javascript">
    $(document).ready(function () {
        $("#non_bench_stock_fields :input").removeAttr("disabled", true);
        $("#bench_stock_fields :input").attr("disabled", true);
        $("#artifact_client_id").change(function () {
            if ($("#artifact_client_id option:selected").text() == "Bench Stock") {
                $("#bench_stock_fields").slideDown("fast");
                $("#bench_stock_fields :input").removeAttr("disabled");
                $("#non_bench_stock_fields").slideUp("fast");
                $("#non_bench_stock_fields :input").attr("disabled", true);
            } else {
                $("#non_bench_stock_fields").slideDown("fast");
                $("#non_bench_stock_fields :input").removeAttr("disabled");
                $("#bench_stock_fields").slideUp("fast");
                $("#bench_stock_fields :input").attr("disabled", true);
            }
        });
        $("#artifact_media_id:enabled").change(function () {
            var enabled_media_id = null;
            enabled_media_id = $("#artifact_media_id:enabled");
            var enabled_evidence_type_id = null;
            enabled_evidence_type_id = $("#artifact_evidence_type_id:enabled");

            if ($(enabled_media_id).find('option:selected').text() !== "Please select") {
                $("#show_selected_media_fields").slideDown("fast");
                $("#show_selected_media_fields :input").removeAttr("disabled", true);
                $.post("/artifacts/show_selected_media_fields", {
                    media_type: $(enabled_media_id).find('option:selected').text(),
                    evidence_type_id: $(enabled_evidence_type_id).find('option:selected').val()
                }, function (data) {
                    $("#show_selected_media_fields").html(data);
                });
            } else {
                $("#show_selected_media_fields").slideUp("fast");
                $("#show_selected_media_fields :input").attr("disabled", true);
            }
            $('#printHere').html(enabled_media_id);

        });

        $("#artifact_evidence_type_id:enabled").change(function () {
            var enabled_evidence_type_id = null;
            enabled_evidence_type_id = $("#artifact_evidence_type_id:enabled");
            if ($(enabled_evidence_type_id).find('option:selected').text() == "Deliverable, (DC)") {
                $("#logical_items_form").slideDown("fast");
                $("#logical_items_form :input").removeAttr("disabled", true);
            } else {
                $("#logical_items_form").slideUp("fast");
                $("#logical_items_form :input").attr("disabled", true);
            }
        });


    });

My ruby view html:

<div id="bench_stock_fields" class="hide">

                <li><%= f.label :evidence_number, :class => "required" %><%= f.text_field :evidence_number %></li>
                <li><%= f.label :evidence_type, :class => "required" %><%= f.collection_select(:evidence_type_id, EvidenceType.where("code='BS'"), :id, :name_and_code) %></li>     
                <li><%= f.label :media_id, :class => "required" %><%= f.collection_select(:media_id, Media.where("name = 'External Hard Drive' or name = 'Internal Hard Drive' or name = 'Thumb Drive'"), :id, :name) %></li>
                <li><%= f.label :received_location,:class => "required" %><%= select_tag(:current_location_id, options_from_collection_for_select(Location.where("location = 'Lab' and rack = 'N/A' and bin = 'Bench Stock'"), :id, :location_name)) %></li>        
</div>
<div id="non_bench_stock_fields" >
--- same fields as above... 
   blah... blah... blah...

============================================================================

OK I wrote a simplified version the code so that it is more understandable. Here is my complete code:

<html>                                                                  
 <head>  
<meta charset="utf-8"> 
 <script type="text/javascript" src="jquery.js"></script>          
<link rel="stylesheet" type="text/css" href="application.css"> 
 </head>                                                                 
 <body>                                                                  
  <script type="text/javascript">                                         
 $(document).ready(function() {
  $("#div_car :input").attr("disabled",true);
  $("#div_car").attr("disabled",true);  

    $("#decide").change(function(){
    if ($("#decide option:selected").text() == 'Car')             { 
              $("#div_car").slideDown("fast"); 
              $("#div_car").removeAttr("disabled");
              $("#div_car :input").removeAttr("disabled");
              $("#div_bus").slideUp("fast"); 
              $("#div_bus").attr("disabled",true);
              $("#div_bus :input").attr("disabled",true);
                } else { 
              $("#div_bus").slideDown("fast");
              $("#div_bus").removeAttr("disabled");
              $("#div_bus :input").removeAttr("disabled");
              $("#div_car").slideUp("fast");
              $("#div_car").attr("disabled",true);
              $("#div_car :input").attr("disabled",true);
              }     
    });

    $("#cars:enabled").change(function(){
    var enabled_select_id = $("#cars:enabled"); 
    $('#printHere').html(enabled_select_id);
    });

 });


</script> 


   <!-- we will add our HTML content here -->  

<div id="div_decide">
<select id = "decide" name="decide">
<option value="buss">Buss</option>
<option value="car">Car</option>
</select>
</div>   

<div id="div_car" class="hide">
<select id = "cars" name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat" selected="selected">Fiat</option>
<option value="audi">Audi</option>
</select>
</div>   
<div id="div_bus">
<select id = "cars" name="cars">
<option value="volvo selected="selected">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
</div>
Enabled Select will print here <br/><br/>
    <span id="printHere"></span>   
 </body>                                                                 
 </html>

My application.css is :

.hide{ display:none;}

Basically here is what I need to do:

I need to load div_car as disabled and hidden. Depending upon the value selected in select “decide”, I need to toggle div_bus with div_car. Depending upon the value selected in CURRENTLY ENABLED select “cars” I need to show something… say print element. It only works for select car in div_bus but does not work when it is toggled with div_car.

  • 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-14T09:31:08+00:00Added an answer on June 14, 2026 at 9:31 am

    I solved this by using html options in rails to set differnet ids for the two collection_selects

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

Sidebar

Related Questions

I am using Asp.net dropdownlist in one of my form ..I have two dropdown
I have two select fields in a form. Every time one of these select
I have two form fields on my view page, a date input (with a
I have two window form applications written in C, one holds a struct consisting
I have two bits of code: a form and a jQuery function. My problem
I have two fields on the form ( forgotpassword form ) username and email
I have two form classes inheriting from a common base. One of the forms
Basically, I have HTML5 markup with two empty divs. I want to use JQuery
I have two divs, one on the left, and one on the right side
I have two DIVs that need to occupy the same space on the page.

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.