Is it possible to choose a concealed HTML radio button by using a designated label?

Attempting to work on a unique project here, creating an HTML calendar that allows users to select a day and submit the form without relying on javascript. Below is a snippet of the HTML code:

<body>
    <form action="/Controller/Select" method="post">
        <table>
            <tr>
                <td>
                    <div class="day">
                        <div>30</div>
                        <div>
                            <input type="radio" name="selectedDay" id="selectedDay_2011_10_30" value="2011-10-30" />
                            <label for="selectedDay_2011_10_30">$1.00</label>
                        </div>
                    </div>
                </td>
                <td>
                    <div class="day">
                        <div>31</div>
                        <div>
                            <input type="radio" name="selectedDay" id="selectedDay_2011_10_31" value="2011-10-31" />
                            <label for="selectedDay_2011_10_31">$1.00</label>
                        </div>
                    </div>
                </td>
                <td>
                    <div class="day">
                        <div>1</div>
                        <div>
                            <input type="radio" name="selectedDay" id="selectedDay_2011_11_01" value="2011-11-01" />
                            <label for="selectedDay_2011_10_01">$1.00</label>
                        </div>
                    </div>
                </td>
            </tr>
        </table>
    </form>
</body>

The CSS style applied is as follows:

.day input {
    display: none;
}

In my testing phase, I noticed that upon clicking the label associated with a radio button, no change occurred in the "checked" attribute of the input element. However, modifying the CSS to:

.day input {
    display: inline-block;
}

Resolved the issue and now the radio button gets checked when the corresponding label is clicked. Any insights or suggestions on how to improve this implementation?

Answer №1

One solution is to hide the radio box when a user clicks on another label by using CSS.

.day input {display: none;}

An alternative method that should work is to make the radio box invisible by setting its dimensions to 0:

.day input {visibility: hidden; width: 0px; height: 0px;}

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 is causing the issue with the italic font not displaying properly?

I am currently learning CSS. I attempted to make a portion of my text italicized, but for some reason, the text refuses to adopt the desired style. Any ideas on what might be causing this issue? .bold { font-weight: bold; } .italic { font-weight: i ...

Utilizing HTML form action to link to a PHP script located in a separate folder

My journey begins here Main: Members/name.html search.php Members is a directory containing my html code in name.html <form action="../search.php" method="get"> <div> &l ...

Notification box appearing on the homepage

I created a landing page featuring various products. Each product is accompanied by a description and price. When you click on a product, a "popup window" should appear displaying the picture and description. My concern is that if I have numerous product ...

Fixing the Bootstrap Datepicker: A Step-by-Step Guide

Is there a way to configure the Datepicker to display today's date and tomorrow's date? Click here for the JS file Check out the image on our website https://i.stack.imgur.com/VyFUB.jpg ...

When utilizing "column-count" with "display: flex", both Firefox and IE will only render a single column

I am struggling to achieve a two-column layout with nested columns inside each one. The code I used looks great on Chrome and Safari, but on Firefox and IE, it only displays in a single column: What mistake am I making here? .two-columns { column-cou ...

What is the best way to center kitchen sink cards horizontally using bootstrap?

I'm having trouble getting my kitchen sink cards to align horizontally. Here's a snapshot of the cards: https://i.sstatic.net/4JIXc.png. Despite trying various CSS and HTML codes, I can't seem to get them to align properly. One code I attemp ...

JavaScript MP3 player

Could someone kindly point out where I went wrong? I am attempting to create an MP3 player using CSS, HTML, and JavaScript. Currently, the script only functions to start or stop the audio file. However, I keep encountering an error message: TypeError: docu ...

Delegate All Events to the Document

In my current setup, I have over 350 events that look like: $(document).on('click','.removable-init',function(){}); I've noticed a performance issue where some click events are delayed by a fraction of a second. This is happening ...

Create a circle at the point where two table cells intersect in an HTML document

How can I create a circular shape at the intersections of HTML tables? I am struggling to figure out a way to incorporate shapes into HTML tables. My goal is to achieve a design similar to the image shown below. I have attempted using text and spans, as we ...

Retrieve the value of the second child element in a table cell when clicking on it with Javascript

I have created a table with one row that includes the title of the month and a cell containing an inner table with multiple rows and cells. I want to display the content of the second cell in the second table as a modal box or alert dialog when it is click ...

Troubleshooting Challenges with Embedding Videos in Wordpress

I'm running into an issue with a heavily customized Wordpress site. Out of nowhere, one of the pages has stopped functioning! The problem arises when attempting to click on a video link, which should open a lightbox clone (prettyPhoto) displaying a Y ...

Can we pause and resume the progress bar using Javascript in conjunction with animationPlayState?

Looking for a way to control a progress bar script that runs for 180 seconds and then redirects the browser? Check out the code snippet below. I've added an onclick event to test pausing the progress bar. My goal is to pause, reset, and adjust the dur ...

Switching the class for the pseudo-element :after

Consider a scenario where there is a button: <button href="#" class="search no-style search-active" style="display: inline-block;"> <div class="pointer" style="display:none">::after</div> </button> Upon activation of the button, ...

What is the best way to create a line break within a loop in React?

I have a react component that I need to format into multiple lines, specifically having 2 boxes on top and 3 below in a looped return. The desired layout is to stack the boxes in 2x2 or 2x3 depending on the total number of boxes generated by the loop. So, ...

Disabling an HTML select option control will prevent it from being included in the form submission

Within my HTML code, I am facing an issue where I want to disable a certain control based on the selection made in another client-side control. To achieve this, I implemented the following jQuery code: $('#dropDown1').attr('disabled', ...

Encountering the message "Error: Unable to access undefined properties (reading 'username')" while making my POST request

My POST request isn't functioning correctly and it's failing to update. The specific error message I'm encountering is: TypeError: Cannot read properties of undefined (reading 'username') app.post('/create-user', functio ...

Tips for identifying repeating id numbers within a form?

I recently completed a form with approximately 800 fields, only to realize that I accidentally gave some of the fields the same ID. Can someone please advise me on how to track down these duplicate IDs? ...

Leveraging font as a comprehensive repository of icons

I have been experimenting with using entypo as the icon source for my web application. The UI technology I am working with is ZK. However, I encountered an issue when trying to include an icon from that font by using: <span sclass="entypoWhite">&am ...

What is the best way to update the src of an input using an onclick event?

When I click the input, my background changes color as expected. However, the src of the input only changes on the second click. How can I make it change the source on the first click? Also, how can I change the src back to the original with a second cli ...

How can I automatically add a specific word that I've highlighted within a <text area> situated within an iframe?

This chrome plugin automatically inserts a designated word into the content of an iframe. Specifically designed for Chrome users. <html> <iframe id="iframe" frameborder="0" src="http://www.maozakor.co.il/demo/default.aspx"> </if ...