Creating HTML forms allows for images to be used as checkboxes

I'm attempting to convert an HTML forms checkbox into a clickable image that changes its appearance when clicked. Additionally, I need it to be capable of storing one or two variables (specifically for generating them with row and column values) and functioning with the submit button.

Apologies if this question seems simple. My expertise lies in C# and some PHP, but now I find myself having to deal with HTML and CSS, which are not my forte.

Answer №1

If you're looking to get started, here's a straightforward example that can be enclosed in a form:

.switch-toggle {
display: none;
}
.switch-toggle + img {
display: inline-block;
}
.switch-toggle + img + img {
display: none;
}
.switch-toggle:checked + img {
display: none;
}
.switch-toggle:checked + img + img {
display: inline-block;
}
<label>
<input class="switch-toggle" type="checkbox" name="img[0][0]" />
<img src="https://picsum.photos/id/1/100" />
<img src="https://picsum.photos/id/2/100" />
</label>
<label>
<input class="switch-toggle" type="checkbox" name="img[0][1]" />
<img src="https://picsum.photos/id/3/100" />
<img src="https://picsum.photos/id/4/100" />
</label>

Check it out on JSFiddle

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

Troubleshooting Div Element Width in CSS Not Functioning

When working on a form design, I encountered an issue where the text labels were not aligning to the same width. Despite setting the width, it didn't seem to work as expected: .form-label { display:inline; width: 160px; } <div class="form-label ...

Choosing individual child elements, with matching names, from two distinct parent elements with identical names

As a beginner in coding, I understand that my code may be messy and redundant, so I apologize for any confusion it may cause. I am working on adding the final piece to my navigation bar. Below is the HTML code, and a fiddle link will be provided at the en ...

Displaying Edit and Delete options upon hovering over the data row

I'm working on a table that uses ng-repeat on the <tr> element. In the last column of each row, I have edit/delete links that should only be visible when the user hovers over the <tr> element. <tr ng-repeat="form in allData | filter:se ...

Are you seeing empty squares in place of Font Awesome icons?

If the Font Awesome icons are displaying as blank squares in all browsers despite correctly linking the stylesheet and attempting to install the package through npm which results in a npm ERR! code E401, it can be frustrating. Even after checking the brows ...

Vue is currently operating in development mode

I keep receiving this notification each time I visit the site: Vue is currently running in development mode. Remember to switch to production mode when deploying for production. Find more helpful tips at .... I came across a solution from someone suggest ...

Receiving a blank ImmutableMultiDict instance via data received from a jQuery request

Having trouble with uploading a file to the server as the ImmutableMultiDict object is coming back empty. upload.html <html> <head> <title>Upload File Ajax</title> <script type="text/javascript" src="https://ajax.googleapis. ...

Unable to get the Gtranslate function to function properly within the drop-down menu

Currently, I am using Gtranslate.io languages on my website with flags displayed without a drop-down menu. Everything is running smoothly but now I am looking to enhance the user experience by placing the flags inside a drop-down list. I want English to ...

Place items at the lower part of the container rather than the top

My <ul> has a fixed height and I want the <li> elements inside it to stack at the bottom instead of the top. I attempted using vertical-align: bottom on the <ul>, but that didn't have any effect. The <li> content may overflow ...

Ways to position divs without causing them to collapse or override existing divs

I am currently developing a demonstration in which users can select jQuery areas to create square blocks. When a user selects an area and adds a comment with color, the entire block is displayed at a specific position. This feature is working perfectly as ...

Show a PDF document on the webpage by making an ajax request in a C# MVC application

Using ItextSharp, I am creating a Pdf from html and trying to show a preview of the Pdf on the screen for the user to interact with. Although the Pdf generation is correct, I am struggling to display it on the screen. Here is the Ajax call: function Pre ...

What is the best way to update an attribute tied to a check box when it is clicked?

Hello, I'm new to Rails and having trouble implementing a seemingly simple feature. Any help would be greatly appreciated. Here's my issue: I'm using this partial to display a list of "Recommendations": <table class="recommendations" s ...

Troubleshooting: Issues with jQuery JavaScript Modal Popup functionality within MVC framework

When I click on the "Comments" link, a modal popup opens up and displays the content as expected. Now onto my issue: In the first scenario, the desired outcome is achieved but some other code does not execute. In this case, when I place the "@section" ins ...

What measures can be taken to restrict users from inputting decimal values?

My website includes an order page where users can input quantities for various items. While some items allow for decimal quantities, others do not. What is the most effective method to restrict users from entering decimal quantities? (Besides using an ale ...

Execute a function once all images have finished loading

My current approach involves utilizing a function to load images from an array: for (var i = 0; i < images_list.length; i++) { var img = new Image(); img.onload = function() { images_objects.push(this); ...

Find the highest-level parent element using JQUERY and select all of its child divs excluding the current

<div class="topDiv"> <div class="repeaterDiv"><input type="radio" id="rpt_01_rb" /> <input type="checkbox" id="rpt_01_cb1" /> <input type="checkbox" id="rpt_01_cb2" /> <input ty ...

Learn how to efficiently execute a function multiple times using pure JavaScript

I am trying to create a tabbed content functionality with multiple elements. How can I utilize the same function for various elements declared in a variable? For example, I want to clone the parent div.tabs element with similar content but different ids an ...

Having trouble displaying nested routes in Angular within the view

I'm encountering some issues with child/nested routes in Angular 4. In the app.module.ts file, my imports statement looks like this: RouterModule.forRoot([ { path: 'templates', component: TemplateLandingC ...

How to turn off and on all elements within a Div tag

Is there a way to disable all elements within a Div tag? I've managed to disable input types successfully, but I'm struggling with links. I attempted the solution provided here, but it didn't work. Here's the code snippet that worked f ...

Looping through items using ng-repeat according to the chosen option in a select dropdown

After expanding my project, I encountered an issue with the main object structure: { screens: [{ id: 0, name: 'Screen0', sections: [{ id: 0, sectionItems: [] }, { id: 1, sectionItems: [] }, { i ...

"Create a dynamic box grid with varying heights using the responsive design features of Bootstrap

I have been attempting to create a responsive grid consisting of 6 textboxes using the box class and bootstrap. My issue is that due to varying amounts of text in each textbox, they end up with different widths/heights. However, I want them all to have th ...