Display interactive content according to radio button selection

I have 4 boxes, labeled a,b,c,d. When the user selects box a, specific content should be loaded:

If image a is picked, load content 1

If image b is picked, load content 2

If image c is picked, load content 3

If image d is picked, load content 4

I want all content to remain hidden until the radio button is clicked. Currently, everything is concealed but clicking on the radio button does not display any content.

Thank you!

<div id="framework">
         <div class="element">
              <img style="float:left;" src="img/left.png" />
              <img style="padding-left:25px; float:left;" src="img/right.png" />
              <img style="padding-left:25px; float:left;" src="img/both.png" />
              <img style="padding-left:25px; float:left;" src="img/without.png" />
          </div>

          <form class="actions">
               <div style="clearfix:none;" class="confirm">
                   <input type="radio" id="frame_left" name="framework">
               </div>
               <div style="clearfix:none;" class="confirma">
                    <input type="radio" id="frame_right" name="framework">
               </div>
               <div style="clearfix:none;" class="confirmb">
                     <input type="radio" id="frame_both" name="framework">
               </div>
               <div style="clearfix:none;" class="confirmc">
                      <input type="radio" id="frame_without" name="framework">
               </div>
           </form>
      </div>
       
       <script>
            $(document).ready(function() {
                // check radio buttons here and show/hide content accordingly
                 $("#navLeft").hide();
                 $("#navRight").hide();

                  if ($("#frame_left:checked").length > 0) {
                       $("#navLeft").hide();
                  }
                 
                  // add onclick functionality here
                 $("#frame_left").click(function() {
                     $("#navleft").show();
                 });

                 $("#frame_right").click(function() {
                      $("#navRight").hide();
                  });
             });
        </script>

        <img id="navLeft" src="img/left.png" />
        <img id="navRight" src="img/right.png" />
   </div>
 

Answer №1

leftNav(utilizing CamelCase) represents the identifier for your DIV, however, you are utilizing leftnav(without CamelCase) in your Script.

You have chosen to conceal rightNav, and if you select frameRight, your JavaScript will once more hide rightNav? Does this seem illogical to you?

Answer №2

My approach would involve using a switch statement and initially hiding the content elements using CSS. Check out a live example here. Regarding the frame_without parameter, it seems like it is meant to display nothing, as it currently does.

$(document).ready(function(){
$('input[name="framework"]').change(function() {
    $('#navLeft, #navRight').hide();

    switch($('input[name="framework"]:checked').attr('id')) {
        case "frame_left":
           $("#navLeft").show();
            break;
        case "frame_right":
            $("#navRight").show();
            break;
        case "frame_both":
           $("#navLeft, #navRight").show();
            break;
         case "frame_without":
            //Not sure what action should be taken here
            break;
    }
});
});

The following CSS code can be used to hide the content by default:

#navLeft, #navRight {
    display: none;
}

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

Tips for handling datetime in angular

Currently, I am working with Angular (v5) and facing an issue related to Datetime manipulation. I am trying to retrieve the current time and store it in a variable. After that, I need to subtract a specified number of hours (either 8 hours or just 1 hour) ...

Tips for using res.json as a callback function

When using a function with a callback parameter, I found that this method works perfectly fine: DB.last(user,(data) => res.json(data)); However, when attempting to refactor it for better readability as shown below: DB.last(user,res.json); The structu ...

Having trouble with the border in Tailwind CSS after integrating Flowbite?

Inside this div is where my component is wrapped: <div className="bg-gray-800 border border-gray-700 rounded-lg"> .... </div> When I installed Flowbite, the border color didn't show up as expected. Check out the borde ...

If IE's conditional comments are dysfunctional

Could this be a silly question? I feel puzzled by it. I've been using an if IE conditional statement to address some issues in IE6. In the head section, this is what I have: <!--[if lt IE 7] > <script type="text/javascript" src="js/ie6.js" ...

Utilize data from two distinct JSON sources that are updated at varying intervals, and display the combined results in an ng-repeat

I am currently working on creating a status list that pulls data from two separate JSON sources. The main purpose of this list is to show general information from the first source, while also indicating a status color based on the number of people in the s ...

Overflowing Bootstrap navbar problem

After adjusting the navbar height, the overflowing issue was resolved, but I specifically want it to be set at 5rem. Currently, the content of the navbar exceeds the 5rem height and mixes with the main body content, regardless of what modifications I make. ...

How can I create an image of a number using Bootstrap?

I have a collection of web pages featuring tiles with various images For example: https://i.sstatic.net/HKna1.jpg Some of my pages look identical to these, but do not include any images https://i.sstatic.net/rLXPY.png In the second screenshot, each ti ...

Is storing HTML tags in a database considered beneficial or disadvantageous?

At times, I find myself needing to modify specific data or a portion of it that originates from the database. For instance: If there is a description (stored in the DB) like the following: HTML 4 has undergone adjustments, expansions, and enhancements b ...

Increasing the size of iframe in a Flexbox layout

I'm facing a challenge in making the iframe element stretch to occupy the remaining space within my web application. While I have ensured that the maximum space is allocated for the div by setting a border, the iframe's height does not automatica ...

What is the process for exporting meshes with morph changes from a threejs application?

I'm having trouble customizing a mesh and exporting it using the gltfExporter from Threejs. Despite my efforts, the export still includes all morph/shape keys, which I want to remove from the final exported mesh. Attempts to clone the scene/mesh have ...

Issue encountered while trying to load electron-tabs module and unable to generate tabs within electron framework

I've recently set up the electron-modules package in order to incorporate tabs within my Electron project. Below are snippets from the package.json, main.js, and index.html files. package.json { "name": "Backoffice", "version": "1.0.0", "descr ...

What is the method used to create the scrolling effect on this website?

I am in the process of creating my own personal website and I would like it to function similar to the following example: Instead of the typical scrolling, I'm interested in transitioning between different sections on the page. Could this be achieved ...

Unlocking Controller Functions in AngularJS Directives: A Step-by-Step Guide

Here is a sample controller and directive code: class DashboardCtrl { constructor ($scope, $stateParams) { "ngInject"; this.$scope = $scope; this.title = 'Dashboard'; } loadCharts () { // some logic here } } export def ...

The issue with Angular 2's Parameterised router link component not fully refreshing

I'm trying to figure out how to show a set of images when I click on a specific menu item. The menu structure looks like this: <ul id="demo23" class="collapse"> <li> <a [routerLink]="['image-gallery','Picasso ...

Crockford's method of replacing values with nested objects

/** Custom Supplant Method **/ String.prototype.customSupplant = function(obj) { return this.replace (/{([^{}]*)}/g, function (match, propPath) { var props = propPath.split('.'); var result = obj; f ...

What is the best way to retrieve the current URL of an external page that is loaded within a jqModal window?

Can the current URL of an external page loaded in a jqModal window be accessed? Additionally, where is the external page located within the jqModal implementation - in an iframe or div? ...

Can you enhance your AutoSuggest feature using jQuery efficiently?

I am currently developing a jQuery AutoSuggest plugin that takes inspiration from Apple's spotlight feature. Below is the basic code structure: $(document).ready(function() { $('#q').bind('keyup', function() { if( $(this).v ...

Package tracking static document within javascript module

I'm currently working on a project in parcel that involves three.js. It appears that I am having trouble loading a 3D model due to an incorrect path issue. My model is located in src/assets/models/mymodel.obj and I am attempting to use it within the ...

Show the information in an array that corresponds to the selected option in a dropdown menu

I have an array with country data and I want to display specific information based on a selected option from a dropdown menu. The 'making_calls' value should be displayed in the .price-call paragraph, and the 'sending_texts' value in t ...

JavaScript namespace problems

Although I am using a namespace, the function name is getting mixed up. When I call nwFunc.callMe() or $.Test1.callTest(), it ends up executing _testFunction() from the doOneThing instead of the expected _testFunction() in the $.Test1 API. How can I correc ...