Assigning a value to a hidden field using a Bootstrap radio button

I'm having some difficulty setting the value of a hiddenfield using a Bootstrap radio button. Below is the code for the button group with the radio buttons and the hiddenfield.

<div class="myRow">
                <div class="smallCol">
                    <div class="btn-group hiddenRFIDValue" data-toggle="buttons">
                        <label class="btn btn-default">
                            <input type="radio" class="btn" name="options" id="alwaysRFID" autocomplete="off">
                            Always
                        </label>
                        <label class="btn btn-default">
                            <input type="radio" class="btn" name="options" id="neverRFID" autocomplete="off">
                            Never
                        </label>
                        <label class="btn btn-default">
                            <input type="radio" class="btn" name="options" id="sometimesRFID" autocomplete="off">
                            Sometimes
                        </label>
                    </div>
                </div>
            </div>
        </div>
        <asp:HiddenField ID="hiddenRFIDValue" runat="server" />

Below is the script I have been trying to use to set the value.

<script>
    $(".hiddenRFIDValue .btn").click(function () {
        // Whenever a button is clicked, set the value of the hidden field
        $("#hiddenRFIDValue").val($(this).text());
    });
</script>

Any assistance with this issue would be greatly appreciated. Thank you.

Answer №1

Hooray! Problem solved. The issue was with the generated HTML changing the ID of the hidden field, requiring the script to be updated accordingly.

<script>
    $(".hiddenRFIDValue .btn").click(function () {
        $("#MainContent_hiddenRFIDValue").val($(this).text());
    });
</script>

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 enabling item draggability following AJAX filtering operations

I have a draggable list of names that can be filtered using checkboxes. When a checkbox is checked, an ajax call is made to filter the names. The list is displayed in an accordion format as shown below: <div id="myAccordion"> <?ph ...

How can we prevent dispatching within a dispatch in React Flux?

It seems that I have come across a situation where I am struggling to avoid the dispatch-within-a-dispatch problem in Flux. While I have found similar questions addressing this issue, none of the solutions provided seem to be ideal, as they often involve ...

Tips for extracting the URL from a JSP using JavaScript

When my JSP returns, it loads a JavaScript that serves as a form action when a button is clicked. This JavaScript includes a request.open() call, with the URL it needs to pass as a peer of the JSP that loaded it. The URL must be the one that was originally ...

Loading SVGs on the fly with Vue3 and Vite

Currently, I am in the process of transitioning my Vue2/Webpack application to Vue3/Vite. Here's an example of what works in Vue2/Webpack: <div v-html="require('!!html-loader!../../assets/icons/' + this.icon + '.svg')" ...

What are the best practices for iterating through asynchronous generator functions?

Suppose we have an asynchronous generator: exports.asyncGen = async function* (items) { for (const item of items) { const result = await someAsyncFunc(item) yield result; } } Can we apply mapping to this generator? In essence, I am attempting ...

What is the proper method for submitting a mail form via AJAX without using jQuery?

Currently, I am working on integrating a PHP mail form with AJAX. The aim is to create a straightforward form that collects user information such as phone numbers and sends it to my email address. While I have managed to set up the form to send emails usi ...

What are effective ways to eliminate script tags from a webpage?

I have implemented tags on my website that users can use to interact with the site. My goal is to figure out how to make the browser only read text from a specific file I write, without any HTML. This should be restricted to certain sections of my websit ...

The Angular 2 http request for a POST method is not initiating

Utilizing Angular 2, I have successfully implemented a get request function. However, when attempting to make a post request, I am unable to detect any sign of the request in the Firebug Net panel. The code for these methods is as follows. Furthermore, th ...

Problems with installing ambient typings

I'm having trouble installing some ambient typings on my machine. After upgrading node, it seems like the typings are no longer being found in the dt location. Here is the error message I am encountering: ~/w/r/c/src (master ⚡☡) typings search mo ...

The MongoDB .push operation is returning a null value

Take a look at the GitHub repository where I am actively working: https://github.com/Stick-z/first-media-app I'm currently in the process of creating a website and focusing on the backend development. One of my tasks involves setting up a jokes array ...

Receiving partial data through the API

My PHP API seems to be experiencing issues when I send data to it using either a post or get request. The strange thing is that the API receives only half of the data. This API functions perfectly fine on localhost, but encounters errors when used on the p ...

Locating a record within a database that contains an objectId field linking to a separate collection

I have defined two collections in the following manner const BookSchema = new mongoose.Schema({ title: String, author: { type: mongoose.Object.Types.ObjectId, ref: "author" } }) const BookModel = mongoose.model(" ...

Tips for effectively nesting HTML Custom Elements visually

I'm currently working on developing a basic HTML Custom Element for incorporating trees into web pages. The code structure I'm using is quite simple, as shown below: <html-tree title="root"> <tree-node title="child1" ...

Warning: The React Router v6's Route component is unable to find the origin of the key props

I recently came across an error in my console and I'm unsure which list is causing it. Is there a way for me to trace back the origin of this error so I can pinpoint where to fix it? The error seems to be related to the React Router component, which ...

Angular 2 dropdown list that allows users to add a personalized value in the HTML code

Here is the scenario I am dealing with We are displaying a fixed dropdown list to the user For example, a dropdown list has 4 options such as apple, orange, grape, pineapple and 'create your own' If the user is not satisfied with the provided ...

Exploring the intricacies of logic through the interactive features of .hover and .click in tandem with Raphael

My goal is to create a hover effect and a click state for a specific area on a map. At present, I want one color to appear when hovering, and another color to display when clicked. Ideally, I'd like the click color to remain even after the user moves ...

Is the user's permission to access the Clipboard being granted?

Is there a way to verify if the user has allowed clipboard read permission using JavaScript? I want to retrieve a boolean value that reflects the current status of clipboard permissions. ...

directive still running despite attempting to stop the service

In my modal window, there is a directive that utilizes a service to make HTTP requests at regular intervals using $interval. However, even after closing the modal window, the service continues to run and make requests every 30 seconds. Is there a way to ...

Is there a method to ensure that only one Bootstrap collapse toggle is active at a time?

When toggling between collapsible cards using two buttons, my goal is to have button2 collapse target1 before expanding target2, and vice versa: <div class="container"> <div class="btn-group mx-auto"> <button class="btn" type="button" da ...

Re-rendering a Highcharts chart for optimal display

I have implemented Highcharts to showcase a set of data through different types of charts - Area chart, Line chart, and Bar chart. By default, the page loads with the Area chart displayed. Upon clicking a button, I switch to displaying the Line chart and t ...