Drop down selection causing Highchart display issue

I'm experimenting with displaying a div that contains a Highchart in this code snippet:

http://jsfiddle.net/ot24zrkt/129/

This line should reveal the container:

$('#container' + $(this).val()).show();
? Fiddle code:

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-more.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>

<select id="category_faq">
    <option value="0">item1</option>
    <option value="1">item2</option>
   <!--  <option value="3">item3</option> -->
</select>

<div id="container1" style="width:500px;height:400px;margin:1.5em 1em;"></div>
<script>
var d = new Date();
var pointStart = d.getTime();
Highcharts.setOptions({
    global: {
        useUTC:false
    },
    colors: [
        'rgba( 0, 154, 253, 0.9 )', 
        'rgba( 253, 99, 0, 0.9 )', 
        'rgba( 40, 40, 56, 0.9 )', 
        'rgba( 253, 0, 154, 0.9 )', 
        'rgba( 154, 253, 0, 0.9 )', 
        'rgba( 145, 44, 138, 0.9 )', 
        'rgba( 45, 47, 238, 0.9 )', 
        'rgba( 177, 69, 0, 0.9 )', 
        'rgba( 140, 140, 156, 0.9 )', 
        'rgba( 238, 46, 47, 0.9 )', 
        'rgba( 44, 145, 51, 0.9 )', 
        'rgba( 103, 16, 192, 0.9 )'
    ],
    chart: {
        alignTicks:false,
        type:'',
        margin:[60,25,100,90],
        // other customizations...
    },
    title: {
        text:'Test Chart Title',
        align:'left',
        margin:10,
        x: 50,
        // other customizations...
    },
    subtitle: {
        text:'Test Chart Subtitle',   
        align:'left',
        x: 52,
    },
    // more configurations...
}); 

// randomData function definition...

// Font import from Google Fonts and body styling...

Answer №1

When the select option is changed, any content within a div will be hidden.

$('#category_faq').on('change', function () {
                      $('div').hide();
                      $('#container' + $(this).val()).show(); 
                  });

Please remove this line of code: $('div').hide();

You can view the demo here: http://jsfiddle.net/ot24zrkt/130/

It's important to note that jQuery 1.6 may not work well with highcharts, so consider using version 1.10 or higher instead.

Answer №2

Check it out here: http://jsfiddle.net/ot24zrkt/133/

This is the HTML code:

<select id="category_faq">
    <option value="1">item1</option>
    <option value="2">item2</option>
   <!--  <option value="3">item3</option> -->
</select>

And here's the JS code:

$('#category_faq').on('change', function () {
     $('div[id^="container"]').hide();        
     $('#container' + $(this).val()).show();
});

To ensure highcharts work properly, make sure you have JQuery version 1.7.2 or higher.

Also, when using the change event, be careful not to hide all divs as this may affect the highcharts generated #highcharts-0 div. Instead, use $('div[id^="container"]').

Lastly, ensure that the option values in #category_faq correspond correctly with the number of #container divs. In your JSFiddle, the option values are set to 0 and 1 (should be 1 and 2), while the first container has an id of #container1.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing Font Awesome icons within a JSON structure

I'm running into a bit of trouble trying to display font awesome icons. The text is written in json using a rakefile, and I'm attempting to insert a font awesome icon within the text. However, I'm facing difficulties because the text is in j ...

Locating items based on checkboxes and dropdown selection

My goal is to calculate the sum of certain numbers based on checkboxes and a select option. Below is the code I am using: <div class="container"> <select> <option value="1">1</option> <option value="2">2</option> <o ...

The select tag containing the ng-model attribute fails to display the preset default value from the controller

Within the pagination feature, a dropdown menu has been included to allow users to select the number of items displayed on each page. However, there seems to be an issue with the default values that have been set in the controller not displaying correctly. ...

Is there a way to have content update automatically?

After writing this block of code, I discovered that clicking on one of the circles activates it and displays the corresponding content. Now, I am looking for a way to automate this process so that every 5 seconds, a new circle gets activated along with its ...

Troubleshooting an Ajax request in Google Scripts with a '$' variable bug

I am trying to implement an AJAX Request using the ajax() method. I have created the functions below on scripts.google.com, but encountered the following error: function AjaxCall() { var arr = { City: 'Moscow', Age: 25 }; $.ajax({ u ...

What could be causing the read-only error in my presentation?

My website has always had a small slider that worked perfectly, but now an error message keeps popping up: Error: "myIndex" is read-only This is the JavaScript code in question: const myIndex = 0; carousel(); function carousel() { let i; const x = ...

Tips on how to update a table following each button click during an ajax request

I am encountering an issue while trying to display data in a table by clicking on a search button. The problem arises when there is no data between the specified "Fromdate - Todate" range; the error message appears correctly. However, even after entering t ...

The form is not functional on Safari and Chrome, but it works perfectly on Internet Explorer and Firefox

Hey everyone, this is my first time posting on this forum. So greetings! I've encountered a problem with an online tool I created for mystery shoppers to encode and validate their visits across Europe. The tool's automatically generated forms, b ...

What is causing the HTML sub menu to appear in the incorrect position?

I'm working on an HTML and CSS menu. I'm trying to center the sub-menu relative to the main menu (ul.menu). Why is there extra space appearing on the left side? The styling for ul.menu li:hover ul already sets left: 0, and its closest parent i ...

Hide a parent div in jQuery depending on the checkbox status

I have a code snippet that I need help with. You can view the code here. $("#filters :checkbox").change(function() { $(".listing-details > div").hide(); $("#filters :checkbox:checked").each(function() { $(".listing-details ." + $(this). ...

I'm having trouble figuring out what's wrong with my code as I attempt to pass values using GET through Ajax to a PHP file

I am having trouble passing a value through a GET request as an Ajax call, but on the PHP page, it shows an undefined index. Here is my code: Any assistance would be greatly appreciated. JavaScript: function showDiv(id) { loadXMLDoc(id); docume ...

Acquire the original Vine video source in .mp4 format on iOS

I've come across some helpful answers in PHP, but I'm wondering if there's a way to achieve the same results with JavaScript or iOS. Here are the links I found: How to get Vine video url (not sure how this is implemented) Get .mp4 source ...

The Android app fails to load web pages on the mobile device

Encountering an issue - I can access a website from my app on a web browser without any problems. However, when I install the same app on my smartphone, it fails to function. The cause of this problem eludes me. ...

A guide to resolving the "ActiveRecord::RecordNotFound" error in Rails for a missing Program ID

While conducting an initial test of my Rails API, I encountered an issue when trying to fetch data from my backend and display the results using console.log() in my browser console. The problem arose when attempting to access a list of programs through my ...

Change the name of total.js to totaljs

Would it cause any issues if I decided to rename the total.js folder to totaljs? Do I need to update any 'require' references? For example, renaming Node_modules/total.js to node_modules/totaljs ...

Unmounting the event post transitioning to a new page

In a component, I have implemented code that checks if the component is visible when scrolling. Here's what the code looks like: constructor(props) { super(props); this.handleScrollAnimation = this.handleScrollAnimation.bind(this); ...

Using Javascript Timers in an ASP.NET AJAX application with the pageLoad() function

function initiatePageLoad() { clearTimeout("MessagesTimer"); clearTimeout("NotificationsTimer"); var MessagesTimer = setTimeout("CheckMessages()", 15000); var NotificationsTimer = setTimeout("CheckNotifications()", 15000); } I've be ...

Enhancing Dataset Quality: Incorporating Failed Results with Apify

We have implemented the Apify Web Scraper actor to execute a URL validation task that retrieves the input URL, the title of the page, and the HTTP response status code. Our testing includes 5 URLs - 4 valid ones and 1 non-existent URL. The successful resul ...

The $() function in jQuery consistently yields 'undefined' when used in conjunction with AJAX requests

I've noticed that the popup shows up before the text in the textbox gets updated. It seems like the JavaScript is being called before the page is fully rendered, which may be causing the 'undefined' popup. How can I ensure that JavaScript is ...

Split a JavaScript string at a mathematical operator while ensuring that the operator is still included in

Hello there, I am attempting to break down a string of text into an array whenever a '+' or '-' is present. First of all, I am looking for a way to split at the plus sign and ensure it is included in the array. I have experimented with ...