The correlation between the input field and the graphic

Hello, I have a question for all you ASP.NET professionals out there: I am working on a project where I have multiple dynamically generated textboxes in a row. Within the same row, there is also an image that has an onclick event handler. My goal is to establish a relationship between the textbox and the image so that when I click on the image and choose a value, the corresponding textbox will be filled. The IDs of my current controls are as follows: Image:

ct100_cph_Detail_rpFields_ct109_rpCell_ct100_cbf_bed1_item_sym
Textbox
ct100_cph_Detail_rpFields_ct109_rpCell_ct100_tb_bed1
I am looking for a solution using JavaScript since I am not very familiar with ASP.NET. Any help would be greatly appreciated! :-)

Answer №1

If the pattern for generating IDs remains consistent, you can easily access the textbox by manipulating the ID of the button or image. Simply replace the unique portion of the button/image ID with the corresponding section from the textbox ID.

For example:

<input type="button"  value="click" 
   id="ct100_cph_Detail_rpFields_ct109_rpCell_ct100_cbf_bed1_item_sym" 
   onclick="document.getElementById(this.id.replace(/_cbf_bed1_item_sym$/,'_tb_bed1')).value='gotcha'"/>

<input type="text" 
   id="ct100_cph_Detail_rpFields_ct109_rpCell_ct100_tb_bed1"/>

There may be alternative methods, but in order to discuss them effectively, it is necessary to examine the markup structure of a specific row to understand the relationship between these elements within the document tree.

Answer №2

The connection between them lies in their shared presence on the same row.

On the server side:

TableRow.Attributes.Add("onclick", "rowClick(event);")

On the client side:

function rowClick(e) {
    e = e || event;
    var target, image, inputBox, selectedRow;
    target = e.target || e.srcElement;
    if (target.tagName == 'IMG') {
        image = target;
        while(target.tagName != 'TR') {
            target = target.parentNode;
        }
        selectedRow = target;
        inputBox = selectedRow.getElementsByTagName('input')[0];
        inputBox.value = image.src;
    }
}

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

Delay loading background image until a specific time has passed, preventing website from fully loading

My website features a vibrant backgroundImage Slideshow that functions seamlessly. However, I am looking to reload the images of the slideshow after a specific time interval. The issue is that the website keeps loading endlessly. Once the website has com ...

Arrange objects on a grid

I've got an array filled with objects, each containing 3 images, a name, and some details. I'm attempting to display these objects on Bootstrap cards, but currently each card is showing up on its own line. My goal is to arrange the cards in a gri ...

JavaScript communication between clients and servers

I am looking to develop two scripts, one for the client-side and one for the server-side. I came across a snippet that allows for asynchronous calling of JavaScript: <html> <head> </head> <body> <script> (function() { ...

Enhancing ASP.net: Expanding functionality of or Including components to Current BoundField

Can a property be added to the current asp:BoundField control without needing to create a new instance like <tst:BoundField></tst:BoundField>? If yes, would you kindly provide an example? ...

My Angular7 app.component.html file is not displaying the routing. What could be the issue?

After implementing the code in app.component.html in Angular 7 like this: <div id="wrapper"> <header id="header-container" class="fullwidth"> <div id="header"> <div class="container"> <div class="left- ...

The format for a DateTime field in a JSON string array is as follows: yyyy-MM-dd hh:mm:ss

I am working with a JSON array string pulled from a database and I need to format the DateAndTime field into yyyy-MM-dd hh:mm:ss. This formatting needs to be flexible as the data passed through will vary, except for the DateAndTime. Here is my current att ...

Issues with Angular Reactive Forms Validation behaving strangely

Working on the login feature for my products-page using Angular 7 has presented some unexpected behavior. I want to show specific validation messages for different errors, such as displaying " must be a valid email " if the input is not a valid email addre ...

Combining server-side and client-side routing in AngularJS: A comprehensive guide

Currently, I am in the process of transitioning a project to an Angular-based Single Page Application (SPA). The project is originally built using node/locomotivejs and serves templates from the server side. Due to its large size, we are converting it to A ...

stop the menu component from triggering a re-render

I am facing an issue where the menu opens and closes briefly when I refresh the page. I want to find a way to prevent this re-rendering process. Every time I refresh, my console.log shows: false 'open' navigation.jsx:23 item navigation.jsx: ...

Strapi: Enhancing User Experience with Unique Passwordless Customization Services

I have been attempting to modify the "passwordless" strapi plugin in order to generate verification codes consisting exclusively of digits. To achieve this, I need to override the createToken function within the plugin's service. Following the instru ...

Orbiting ThreeJS object positioned at the coordinates (0,0,0)

I have set up a ThreeJS Scene similar to the image provided. The issue I'm facing is when trying to rotate Obj2 vertically around Obj1, it ends up rotating around the Z axis instead of the center point (0,0,0). My goal is for Obj2 to orbit exclusively ...

Upon redirection, my JavaScript codes cease to function properly and require a page refresh to resolve

Upon redirecting to another page with included JS codes, my main.html does not function properly until I refresh the page. What steps can be taken to resolve this issue? 0.html <body data-theme="b"> <div class="p2" data-role="page" id="p2"> ...

Tips for utilizing a resource Dll for various cultural settings

I have created a DLL called DynamicResourceDLL for various cultures as shown below DynamicResourceDLL.Cart.Cart //English DynamicResourceDLL.Cart.Cart_de_DE DynamicResourceDLL.Cart.Cart_es_ES DynamicResourceDLL.Cart.Cart_fr_FR I have added the DynamicRe ...

Mixing cookie and token authentication in ASP.NET Core

Currently, I have a project in ASP.NET Core 2.1 that includes both REST services (Web API) and an admin panel (MVC). I am looking to enhance the security of my API by implementing JWT token authentication, while also using cookies for securing my MVC pag ...

Does the code I've written successfully interact with the AJAX request I'm attempting to make to the Servlet?

I am currently in the process of verifying whether the AJAX Call present in my js file is functioning correctly and sending information back to the Servlet. My goal is to understand how to utilize the response from the servlet to display the user-provided ...

Guide to displaying a component within the Vue instance

I am currently in the process of developing a Nuxt module that will not interfere with the main Nuxt application. My approach involves creating a separate Vue instance and mounting it as a child node under the body element, similar to a child node to the _ ...

The addition operator cannot be used with the Number type and the value of 1

Encountering an issue where the operator '+' cannot be applied to types 'Number' and '1' buildQuerySpec() { return { PageSize: this.paging.PageCount, CurrentPage: this.paging.PageIndex + 1, MaxSize: '' ...

Leveraging electron-usb alongside electron

I attempted to integrate the electron-usb library into my electron project. Upon running npm start with require('electron-usb') in my index.html file, an error is displayed in the console: Uncaught Error: The specified procedure could not be fo ...

Is there a way to extract values from a particular object?

Currently, I am utilizing a JSON server to establish a straightforward login system. The data stored on the server is structured as follows: { "users": [ { "name": "user1", "password": "pass1", "email": "<a href="/cdn-cgi/l/emai ...

How can I retrieve neighboring cells from a 2D array using Javascript?

I'm currently following a tutorial on creating grid-based games using vanilla JavaScript. The tutorial I'm referring to can be found at https://www.youtube.com/watch?v=aKYlikFAV4k&t=1848s&ab_channel=TheCodingTrain However, I'm facin ...