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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:39:39+00:00 2026-05-24T11:39:39+00:00

this is a classic question but can’t find the best approach. I have a

  • 0

this is a classic question but can’t find the best approach. I have a dropdown with id project_billing_code_id and 3 values (1, 2, 3).

If value selected = 1 then show div with id one and only this one. div two and three must be hidden.
I also want to make this happen when view is loaded so not only on change.

$(document).ready(function() {
  $("#hourly").hide();
  $("#per_diem").hide();
  $("#fixed").hide();
$("#project_billing_code_id").change(function() {
  if ($("#project_billing_code_id").val() == '1') {
   $("#hourly").show();
   }
  else if ($("#project_billing_code_id").val() == '2') {
   $("#per_diem").show();
   } 
  else if ($("#project_billing_code_id").val() == '3') {
   $("#fixed").show();
   }
  else { 
       $("#hourly").hide();
       $("#per_diem").hide();
       $("#fixed").hide();
       }
  });
});
  • 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-24T11:39:40+00:00Added an answer on May 24, 2026 at 11:39 am

    You were close. You probably want a few small tweaks to the behaviours to make sure all the divs hide and that correct div is showing on page load.

    Have a play with the code here: http://jsfiddle.net/irama/ZFzrA/2/

    Or grab the updated JS code here:

    hideAllDivs = function () {
        $("#hourly, #per_diem, #fixed").hide();
    };
    
    handleNewSelection = function () {
    
        hideAllDivs();
    
        switch ($(this).val()) {
            case '1':
                $("#hourly").show();
            break;
            case '2':
                $("#per_diem").show();
            break;
            case '3':
                $("#fixed").show();
            break;
        }
    };
    
    $(document).ready(function() {
    
        $("#project_billing_code_id").change(handleNewSelection);
    
        // Run the event handler once now to ensure everything is as it should be
        handleNewSelection.apply($("#project_billing_code_id"));
    
    });
    

    Let us know how you go!

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

Sidebar

Related Questions

This is kind of a dumb question, but I can't seem to find the
I know this must have been answered before here, but I simply can't find
I think this might be a classic question but I am not aware of
I know this is something of a classic question, but does the mysql/grails (deployed
I must apologize if this is a duplicate question, but I can't seem to
This isn't a classic programming language question, but it's keeping me busy so I
In classic ASP, you can dump a recordset into an array using getRows(). This
I have a select box on a classic ASP page which looks like this:
This is a classic CS problem I encountered in my work: I have a
Not sure this is a programming question, but we use LaTeX for all our

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.