Is there a way to implement a particular CSS style based on a user's selection in a checkbox?

Is there a way to implement specific CSS code based on user choices made in checkboxes? I need the CSS to change dynamically according to what the user selects.

For example:

  1. If Platform = Unix, Windows, and Network are selected, execute the CSS for Unix, Windows, and Network.
  2. If Platform = Windows and Network are selected, execute the CSS for Windows and Network.

This functionality will be utilized in a content editor within a SharePoint calendar list.

Please see the code snippet below:

<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
function SubmitClicked(){
// JavaScript code to handle user selections and generate corresponding CSS
}
</script>

            // CSS Rules for Unix
            .ms-acal-color1 div, .ms-acal-color1 div a, .ms-acal-apanel-color1 SPAN {
                display: none;
            }

            .ms-acal-color1{
                display: none;
            }
            
            .ms-acal-selcolor1{
                display: none;
            }
            
            .ms-acal-apanel-color1{
                display: none;
            }

            // CSS Rules for Windows
            .ms-acal-color2 div, .ms-acal-color2 div a, .ms-acal-apanel-color2 SPAN {
                display: none;
            }

            .ms-acal-color2{
                display: none;
            }
            
            .ms-acal-selcolor2{
                display: none;
            }
            
            .ms-acal-apanel-color2{
                display: none;
            }

            // CSS Rules for Network
            .ms-acal-color3 div, .ms-acal-color3 div a, .ms-acal-apanel-color3 SPAN {
                display: none;
            }

            .ms-acal-color3{
                display: none;
            }
            
            .ms-acal-selcolor3{
                display: none;
            }
            
            .ms-acal-apanel-color3{
                display: none;
            }
        

            <div>Platform</div> 
            <input id="platform" checked type="checkbox" name="platform" value="Unix">Unix
            <input id="platform" checked type="checkbox" name="platform" value="Windows">Windows
            <input id="platform" checked type="checkbox" name="platform" value="Network">Network<br><br>
            <br/>
            <input type="button" onclick="SubmitClicked()" id="go" value="Submit">
        

Answer №1

Make sure to update the tag class based on the checkbox's status change. Check out this resource

Alternatively, you can utilize the :checked CSS pseudo-class. Here's a helpful guide

input[type=checkbox] + label {
  color: #ccc;
  font-style: italic;
} 
input[type=checkbox]:checked + label {
  color: #f00;
  font-style: normal;
} 
<input type="checkbox" id="ossm" name="ossm"> 
<label for="ossm">CSS is Awesome</label> 

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

What are the proper steps to ensure images are displayed correctly on mobile devices?

https://i.sstatic.net/M68Ob.jpg https://i.sstatic.net/fPKXr.jpg Our background image is 1920x1080p and looks great on desktop browsers, but it's not displaying properly on mobile devices in either portrait or landscape mode. Is there a way to resolv ...

Passing a textbox's value through an AJAX call from a ServerSide datatable in MVC5

I am encountering an issue with my server-side data-table. After making an ajax call, the value from the text box is not being sent - instead, it is sending an empty value. However, everything works fine when I pass static data. Here is the code that wo ...

Managing JavaScript promise rejections

What is the best approach to managing an error, such as the one labeled "new error" in the code snippet below, that occurs outside of a promise? function testError() { throw new Error("new error") // How can this error be properly handled? var p ...

Searching for a document using the $eq operator in MongoDB within the context of Next.js - what is

In my Next.js code, I am fetching a document from MongoDB using a unique slug. Here is the code snippet: export async function getStaticProps(context) { const postSlug = context.params.postPage; const { db } = await connectToDatabase(); const posts ...

The Express.js static() function seems to have trouble serving files from subdirectories that are more than one level deep

My Express.js app has a folder structure displayed on the left. Line 19 utilizes static(). The path for './client' is defined, with path.join() included as well. In the network log on the right, all assets load properly except for the components ...

Error encountered with Vuetify stepper simple component wrapper and v-on="$listeners" attribute

I'm working on developing a custom wrapper for the Vuetify Stepper component with the intention of applying some personalized CSS styles to it. My aim is to transmit all the $attrs, $listeners, and $slots. I do not wish to alter any functionality or ...

What is the process for implementing a simple bootstrap design similar to the one featured in the Laravel 5 tutorial?

I recently started using Laravel. After installing Laravel 5 on my Windows 7 machine with WAMP, I began working through the intermediate task tutorial on the Laravel documentation (http://laravel.com/docs/5.1/quickstart-intermediate). The tutorial includes ...

Is it possible to execute a PHP command using JavaScript?

Successfully invoking PHP from JavaScript using AJAX: function fun() { var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState == 4) { document.getElementById("content").innerHTML = xhr.responseText ...

Footer not adhering to the bottom of specific pages

I have been using the code snippet below to ensure that most of my pages stick to the bottom. However, I've noticed that the ones that don't are sub-menu items that contain a contact form with captcha. I'm not sure what's causing this i ...

Trigger an Ajax request upon user confirmation, which will only be prompted based on the result of a previous Ajax call

Currently, I am facing a challenging issue surrounding asynchronous calls: A specific JQuery function is triggered on user click. This function then requests a PHP file to check if the user input overlaps with existing information in the database. If an o ...

Execute jQuery code only when a child element within the parent container is clicked

Within a div section, I have included various child controls like dropdowns and check boxes. I am seeking to implement some jQuery code that will be triggered when any of the child elements are clicked, excluding clicks on the empty space within the div. ...

Sharing information between React and Formik components

As a React beginner, I am venturing into creating my first ToDo App. At the moment, I have two components set up - one for inputting data using Formik and another where I plan to display this data. I am unsure about how to effectively pass data between th ...

Loading HTML and jQuery dynamically using AJAX

I am struggling to access a child element of HTML that is loaded dynamically through AJAX. Unfortunately, it's not working as expected. $.get('test.html', function(data) { var content = $('#content', data).html(); conso ...

Unable to establish an external connection with the node

Currently, I am in the process of establishing a connection to a local server and running an app on port 8080 using node. Both node and apache are installed on my system. When Apache is active, I can access the server externally. However, when Node is runn ...

Convert to cshtml and retrieve the logged-in user's identification

I'm completely new to using AngularJS. I recently developed a demo login app, but I'm facing an issue where the page doesn't render even when the login id and password are correct. Code: app.controller('MainCtrl', ['$scope&ap ...

Dynamic Arrow Connection Featuring a Label

Struggling to visualize directed links with a label in a force graph using D3. Here's the code I am working with: // Per-type markers, as they don't inherit styles. var svg = d3.select("body").select("svg"); svg.append("svg:defs").selectAll("ma ...

Preserving scroll location following a hyperlink postback situation

I've explored numerous strategies to tackle my issue, but none have proven successful. My task involves toggling user activation and deactivation through an asp.net hyperlink. The main problem arises when this action triggers a postback, causing the p ...

Firefox experiences failure with Ajax while all other browsers are functioning properly

I've seen discussions on various forums and websites regarding the issue with Firefox browser failing to refresh a CAPTCHA image created in PHP when a button is clicked. I've tried multiple scripts, all of which work perfectly in Edge, Chrome, Sa ...

Excessive background image size causing issues on iPad 4

Upon launching the website on an iPad4 in portrait mode, I noticed that the background image is too high, matching the height of the section set to 100vh. Is there a way to adjust the background image to be shorter? Here is the link to the website for re ...

Creating a CSS style that automatically adjusts the font size within a container that spans the full height of the

Issue: I have a container set to 100vh, but as the screen size changes, I want the font size to adjust accordingly and always stay within the container without overflowing. Thoughts: While I understand this can be achieved easily with @media CSS rules, I& ...