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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:46:30+00:00 2026-05-27T07:46:30+00:00

I have two spans that appear or hide when their respective option is selected

  • 0

I have two spans that appear or hide when their respective option is selected from a select-menu. By default, both spans are set to display: none in CSS. I would like to maintain the visibility of any currently visible span after the page reloads (in case there was a validation error, for example).

I did this with a checkbox and it was easy, but I can’t figure it out with a select-menu.

    // Toggles the div based on selected option
$(function() {
    $('#maintenanceIntervalId').change(function() {
        var value = $('#maintenanceIntervalId option:selected').val()

        switch(value) {
            case "2": {
                $("#weekly-maintenance-on").show();
                $("#monthly-maintenance-on").hide();
                break;
            }
            case "3": {
                $("#monthly-maintenance-on").show();
                $("#weekly-maintenance-on").hide();
                break;
            }
            case "1": {
                $("#weekly-maintenance-on").hide();
                $("#monthly-maintenance-on").hide();
                break;
            }
        }
    });
});

The above works as expected. But in order to get the currently visible span to stay visible after page reload, I moved the switch statement into its own function toggleMaintenanceDiv() and added the following line:

toggleMaintenanceDiv($('#maintenanceIntervalId option:selected'))

This does not work, however.

HTML:

<select id="maintenanceIntervalId">
    <option value="1">Day</option>
    <option value="2">Week</option>
    <option value="3">Month</option>
</select>

<span id="weekly-maintenance-on">Stuff one</span>
<span id="monthly-maintenance-on">Stuff two</span>
  • 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-27T07:46:30+00:00Added an answer on May 27, 2026 at 7:46 am

    The script is reloaded each time with page loading, all variables or states of javascript will be lost after reloading. I think you can store the visible span IDs in cookie and when the page loads each time, it checks the cookie first and sets corresponding spans visible.

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

Sidebar

Related Questions

I have a ninput and two spans, each with a jquery ui icon that
So I have a list of divs that appear in a vertical order. Two
I have two span elements that I would like to stay on the same
I have two applications written in Java that communicate with each other using XML
I have two identical tables and need to copy rows from table to another.
I have two CSS files in my web app: reset.css and screen.css. They appear
I have a window that displays text. There are two parts to the text:
I have a really long table in LaTeX that spans several pages and is
I have two divs. I want one with id hor_rule to appear beneath the
I have two DIVs, first one has a link in it that contains the

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.