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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:55:18+00:00 2026-05-24T12:55:18+00:00

im relatively new to ROR, and would like some help with the following code.

  • 0

im relatively new to ROR, and would like some help with the following code.

I would like to show a div (it’s called demographics) when a specific selection (“Customers”) is made form a dropdown. If an option other than “Customers” is selected from the dropdown, I would like that the demographicsv div remain hidden.

At present, my code is partially working. It shows and hides the div; however, when I save the page and come back to it, the div is hidden, even if “Customers” is selected in the dropdown. This might be because the default setting is: display:none.

Is there a way to make sure that the field is displayed on page load when the proper selection has been made?? And I suppose a way to make the opposite true too–> a div with display:block; remains hidden if the field from the dropdown does not match the required field.

Any help would be extremely appreciated. Thank you and I sincerely appreciate your time:

my code (HAML):

= f.select :who, WHO, {}, :onChange => "showDemographics(this)", :prompt => true

#demographics{:style => "display:none;"}
  %p.information
    please fill out the following demographics.
  %div{:class => "label_leftalign field"}
    = f.label :age, "Age"
    = f.select :age, AGES, :prompt => true
  %div{:class => "label_leftalign field"}
    = f.label :race, 
    = f.select :race, RACES, :prompt => true

Javascript

  function showDemographics(obj)
  {
    if(obj[obj.selectedIndex].value == 'Customer')
    {
        document.getElementById('demographics').style.display = 'block';
    }
    else
    {
        document.getElementById('demographics').style.display = 'none';
    }
  }

EDIT::
OK, So the key issue is that on page reload a div remains hidden even if the correct value is in the dropdown box. I suppose that this can be solved by one of two ways 1. running some sort of validation on everytime the page is loaded or 2. cookies.

Unfortunately, I’m not very well versed in Javascript or jQuery… and I’ve never implemented cookies on a site, and would prefer to avoid using them if possible.

Could anyone help me write a script that validates the presence of Customer in the dropdown and shows/hides a div accordingly? Thank you, and thanks to Carlos Pardilla and M. Cypher for their help thus far.

  • 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-24T12:55:19+00:00Added an answer on May 24, 2026 at 12:55 pm

    The answers above where correct in their own way… the link below shows the actual code that is required for the conditional statement on page load:

    show hidden divs on refresh

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

Sidebar

Related Questions

Relatively new to JQuery. I've got some code that does a banner swap with
I'm relatively new to Javascript, and I'd like to run the piece of code
I'm relatively new to Nant, what i'd like to do is have a task
Relatively new to Python, and I saw the following construct in the PyFacebook library
relatively new programmer here. Look at the two classes defined below. I'd like to
I am relatively new to RoR. In my RoR project I need a mechanism
I am relatively new to codeigniter and am struggling to understand how would save
I'm relatively new to testing and still getting my head around some of the
I'm relatively new to Perl, writing some XML parsing scripts. I have done two
Relatively new to rails and trying to model a very simple family tree with

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.