Retrieving the hidden field value from a list view with JavaScript

Custom Script:

$(document).ready(function() {
    //Customize these values to personalize your modal popup
    var align = 'center';                               
    var top = 100;                                  
    var width = 500;                                    
    var padding = 10;                                   
    var backgroundColor = '#FFFFFF';                      
    var source = 'AttractionDetails.aspx?AttractionID=  **RETRIEVE_VALUE_FROM_HIDDEN_FIELD** ';                                 
    var borderColor = '#333333';                            
    var borderWeight = 4;                                   
    var borderRadius = 5;                                   
    var fadeOutTime = 300;                                  
    var disableColor = '#666666';                           
    var disableOpacity = 40;                                
    var loadingImage = 'lib/release-0.0.1/loading.gif';     

    //Initialize the modal popup when clicking on an element with class "modal"
    $(".modal").click(function() {
        modalPopup(align, top, width, padding, disableColor, disableOpacity, backgroundColor, borderColor, borderWeight, borderRadius, fadeOutTime, source, loadingImage);
    });

    //Close the popup when the escape key is pressed
    $(document).keyup(function(e) {
        if (e.keyCode == 27) {
            closePopup(fadeOutTime);
        }
    });

});

LISTVIEW:

<ItemTemplate>
                        <td id="Td6" runat="server" style="background-color: #FFFFFF; color: #000000; width: 120px;">
                            <asp:Label ID="AttractionNameLabel" runat="server" Text='<%# Eval("AttractionName") %>' />
                            <br />
                            <a class="modal" href="javascript:void(0);"> Modal Pop Up </a>
                            <asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Eval("AttractionID") %>' />

                        </td>
                    </ItemTemplate>

I am looking to extract the value from the HiddenField of the clicked item [when clicking on the hyperlink "Modal Pop Up"] using JavaScript.

Appreciate your help!

Answer №1

By avoiding the use of a hidden field, you can still achieve the same result. Simply add a data attribute and assign it the AttractionID value. This way, there is no need to rely on hidden fields for storing or passing values.

<a class="modal" href="javascript:void(0);" data-AttractionID='<%# Eval("AttractionID") %>'> Modal Pop Up </a> 

Retrieve the AttractionID associated with the anchor tag

 $(".modal").click(function() {
        valueofAttractionID = $(this).data('AttractionID');
        modalPopup(align, top, width, padding, disableColor, disableOpacity, backgroundColor, borderColor, borderWeight, borderRadius, fadeOutTime, source, loadingImage);
    });

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

Extracting information into an Array and transferring it to a ComboBox using C#

I have a database with user data such as names, usernames, and images. I want to display the names in a combo box and show the corresponding image when an item is selected. To achieve this, I have created classes User and UserDB. Here is the code from my U ...

Has the binary search operation not been executed?

My attempt to implement the binary search algorithm in my code example is not producing the expected result. I'm unsure of the cause. Can someone please explain it to me? var array = [1, 4, 6, 8, 9, 12, 15, 17, 19, 34, 55, 78, 80]; function binarySe ...

"What could be the reason behind the sudden disappearance of the TinyMCE icon in my Vue

Welcome to my unique website design! https://i.sstatic.net/rtEwF.png Check out the special tinymce code I created https://i.sstatic.net/8su0i.png https://i.sstatic.net/9y2AO.png ...

Find the total sum of numbers associated with strings that are repeated in two separate arrays

Consider the following scenario where I have 2 arrays: categories = ["hotels", "transfers","food","transfers"] amounts = [1500, 250, 165, 150] The goal is to create an object that will look like this: result = {hotels: 1500, transfers: 400, food: 165} ...

The require statement in Vue.js is failing to function dynamically

Having trouble dynamically requiring an image in Vue.js and it's not functioning as expected <div class="card" :style="{ background: 'url(' + require(image) + ')',}"> export default { data() { return { ...

Swapping out foreach for a LINQ query

I'm currently working on a method that contains the following code snippet: foreach (var s in vars) { foreach (var type in statusList) { if (type.Id == s) { Add(new NameValuePair(type.Id, type.Text)); b ...

Dapper is throwing an error message stating "Data too long for field."

I'm encountering an issue that states: String or binary data would be truncated. This error occurs when I execute the following line of code. Despite researching extensively, I haven't been able to pinpoint the cause. Most resources related to ...

Looking to fill a text field with email addresses by selecting checkboxes for various towers

I have 4 towers and I need checkboxes for each of them. Upon checking any combination of them, the 'txtNotifTo' textbox should be populated with the respective group of email IDs for each tower selected. Could you please assist me in identifying ...

Downloading the file from the specified URL is taking too much time when using the save as blob function

I have developed a service to retrieve and save files from a specified URL. (function() { angular.module('SOME_APP') .service("downloadService", downloadService); function downloadService($http){ var downloadFil ...

The Express Validator is unable to send headers to the client once they have already been processed

I recently integrated express-validator in my Express JS project, but encountered a warning when sending invalid fields to my api: UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client This ...

Is there a limit to the number of else if statements I can use? The final else statement

How can I enhance this code snippet? The last else if statement is not working, despite my efforts to fix it. var selectedDntTyp = $("#donationTypDD"); if (selectedDntTyp.length > 0) var DropInitValue = selectedDntTyp.val(); if(DropInitValue == &apos ...

Eliminating identical characters shared between two strings

I am looking to eliminate any characters that match between two strings. For example: string str1 = "Abbbccd"; string str2 = "Ebbd"; From these strings, I want the output to be: "Abcc", where only the matching characters present in both str1 and str2 ar ...

Get rid of the seconds in the output of the toLocaleTimeString

The method Date.prototype.toLocaleTimeString() provides a language-sensitive representation of the time part of a date in modern browsers. Unfortunately, this native function does not offer an option to exclude the display of seconds. By default, it shows ...

Passing data between API tests in JavaScript

I'm encountering an issue where I need to create e2e api tests. The goal of the first test is to obtain a token for an unauthorized user, use that token in the method header for the second test to return a token for an authorized user, and then contin ...

Issue with Angular binding not updating after being assigned in promise.then() function

Within my angular application, I have a $scope variable labeled as user which contains a name property. Whenever I click on a link to set this user variable to "test": <a href="#" ng-click="setUser()">Set User</a> Using the following functio ...

Maintain continuous visibility of horizontal scroll in Bootstrap responsive tables

When utilizing responsive bootstrap tables in a .net web application to showcase data, the issue arises when a substantial amount of information is returned. In such cases, a horizontal scroll bar appears at the bottom of the page. This forces users to s ...

How can I fetch the current date in ASP.NET directly from the internet instead of relying on the system date?

As I work on creating an app featuring a booking engine, it is essential for me to retrieve the date from the internet. System.DateTime.UtcNow Although I initially used System.DateTime.Now, it provided me with the current (local) system date. As this da ...

Nested object type checking is not being performed

I have been developing an Angular application and working with two interfaces: IAbc and IXyz. interface IAbc { id: number, name: string } interface IXyz { id: number, value: string | number | Date | IAbc[]; } In my code, I initialize a va ...

My current scroll animations are problematic as they are causing horizontal scrolling beyond the edge of the screen

I've implemented scroll animations on various elements of a website I'm constructing. The CSS rules I'm utilizing are as follows: .hiddenLeft { opacity: 0; filter: blur(5px); transform: translateX(-090%); transition: all 1s; ...

Animating with jQuery to a specific offset or position

Currently, I am utilizing jQuery animate to modify the location of an element: $('#item').animate({'top' : '-50'}, 0); The goal is to set the position without any animations. I experimented with both offset and position, but ...