Display radio buttons depending on the selections made in the dropdown menu

I currently have a select box that displays another select box when the options change. Everything is working fine, but I would like to replace the second select box with radio buttons instead. Can anyone assist me with this?

 .sub{display:none;}

 <script type="text/javascript>
 var $subs = $('select.sub');
 $('select').first().change(function () {    
 $subs.hide();
 if (this.selectedIndex > 0)
   $subs.eq(this.selectedIndex - 1).show();
 }).change();
</script>

 <select><--!main select box-->
 <option value="">select</option>
 <option> one</option>
 <option> two </option>
 </select>

 <select class="sub">
 <option> one 1</option>
 <option> one 2</option
 </select>

 <select class="sub">
 <option> two 1</option>
 <option> two 2</option>
 </select>

Instead of using two select boxes as shown above, this is the desired layout:

<div class="sub">
<input type="radio">one 1
<input type="radio">one 2
</div>

 <div class="sub">
<input type="radio">two 1
<input type="radio">two 2
</div>

Answer №1

Is this the desired outcome for you?

<select>
 <option value="">choose</option>
 <option value="sub1"> one</option>
 <option value="sub2"> two </option>
 </select>

<div class="sub sub1">
<input type="radio">one 1
<input type="radio">one 2
</div>
<div class="sub sub2">
<input type="radio">two 1
<input type="radio">two 2
</div>


$('.sub').hide();

$('select').on('change', function(){
    $('.' + this.value).show();
});

View working demo

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

Turn off the option to select a specific time from the dropdown menu on the datepicker. Additionally, if a particular

I have successfully implemented most of the code I need, but I require assistance with one final aspect. jQuery("#date_num").datepicker({ beforeShowDay: function(d) { var day = d.getDay(); var array = ['28/09/ ...

The JSON object is not providing the length of the array, returning the value as

I'm currently fetching JSON data from a PHP file in the following manner: $.getJSON('fresh_posts.php',function(data){ global_save_json = data.freshcomments; var countPosts = data.freshposts; var howManyPosts = countPosts.length; ...

Issues with triggering onScroll event in Internet Explorer 11

<html> <head> <style> div {`border: 1px solid black; width: 200px; height: 100px; overflow: scroll;` } </style> </head> <body> <p>Experience the magic of scrollbar within ...

Is Node.js or Express.js a server-side language like PHP or something completely different?

Hello, I have a question about Node.js and Express.js. I come from a PHP background and understand that PHP operations and functions execute on the server and return results to the client's screen. In simple terms, does Node.js/Express.js serve the s ...

Instructions for making a crossword-inspired grid using a high quantity of divs or alternative elements

I am looking to create a grid on the screen of a web browser or mobile device, with each grid item containing just one letter. It's similar to a crossword puzzle, but taking up most of the screen. I've tried using divs for this purpose, but it se ...

IE7 is not applying the conditional CSS styles to content loaded through AJAX

I am currently tackling some challenges with IE7 compatibility in a Rails application that I am developing. It appears that CSS styles implemented from a stylesheet applied with a conditional comment are not being rendered properly when using HAML like thi ...

What is the way to bypass certificate validation when making a Fetch API request in the browser?

The code snippet below is currently being executed in the browser: const response = await fetch(`${url}`, { method: 'POST', headers: { Authorization: `Basic ${authorization}`, }, body: loginData, }) Upon calling this co ...

Creating slanted lines using CSS / Bootstrap 3

I'm trying to create a webpage with slanted lines. Is it possible to set an angle of 20 degrees using three div elements? Currently, I have one div for the logo at the center and another for the navigation bar. I want the navigation bar to align with ...

Having trouble with the serializing process in Laravel when using Ajax POST requests

<form id="contact" action="/submit_message" method="POST"> <input type="hidden" name="_token" value="{{ csrf_token() }}"> <div class="form-group"> < ...

Issue with text decoration in Html, Css, and Bootstrap

this image shows the issue Hi there, I'm facing an issue with my project involving bootstrap. Whenever I include bootstrap in my project using a link, all "a" tags end up with text decoration. How can I fix this problem? ...

When utilizing npm install buefy and npm install font-awesome, there may be an unnecessary display of [email protected] and [email protected] extraneous errors

After installing buefy and font-awesome, I noticed that it is marked as extraneous and the folder appears with an arrow icon but is empty. How can this issue be resolved? For example: +-- <a href="/cdn-cgi/l/email-protection" class="__cf_email__" ...

`The Issue with Ineffective Slider Removal`

Below is the complete code: import React, { Component } from "react"; import "./App.css"; import Slider from "@material-ui/core/Slider"; import Typography from "@material-ui/core/Typography"; class App extends Compo ...

Text that appears as an HTML button is displayed after being compiled using the $

I am attempting to generate a pop up dialog with two buttons using JS code in angular. The script below is what I am using to create the buttons... var html = $('<button ng-click = "cancelAlert()" > Cancel</button > <button ng-click="c ...

Encountering an error with my JSONP call

Similar Question: json with google geocoding api json Uncaught SyntaxError: Unexpected token : $.getJSON('http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true&callback=?', function(data) { ...

Design a dynamic div element for banners that adjusts to different screen

Is there a way to create a responsive div similar to the img-responsive class in Bootstrap, but for a div element that changes its height relative to its width when the window size is adjusted? For example, if you look at the slider on this website "", yo ...

A mysterious property appearing in a Webpack plugin

Here is my webpack configuration file and package.json. When I execute the command webpack -w, I encounter the following error (shown below). I suspect it may be related to path strings. Any help would be greatly appreciated. webpack.config.js const HtmlW ...

Transfer the information of a selected element to a different element

Hello, I am trying to transfer content from a child element to another element. In my HTML setup, there is a hidden div named "DetailsExpanded" and multiple items called "IconWrapper". When an "IconWrapper" is clicked, I want to copy the content of its "I ...

What is the method for breaking a statement within an if statement on Blogger when both the IF and ELSE conditions are met?

I'm making some adjustments to the labels on my blog to ensure that each post has at least two labels. The concept is that if a post has LABEL 1, it will load one script, otherwise it will load another. However, I've encountered a situation wher ...

Tips for accessing JSON data with jQuery

Hey there! I am a newcomer to Jquery and struggling with how to work with json data. I have received a Json response, but I'm unsure of how to utilize it properly. In my success function, I currently have the following: success: function(resp) { ...

The Bootstrap 4 dropdown seems to have a one-time use limit

I'm currently working on a dropdown menu using Bootstrap 4. The dropdown menu is functional, but I'm facing an issue where it only toggles once. I have tried various solutions recommended on different websites, but none of them seem to work. Belo ...