Maximizing the potential of asp.net and javascript when dealing with multiple fields and the onchange

My asp.net webpage is filled with numerous textboxes, each triggering a JavaScript function on the onchange event. The script changes a textbox to 'Y' to indicate which section of the page has been altered.

While everything functions correctly, I am seeking a more efficient way to handle the onchange calls, given that I have over 100 textboxes with repetitive onchange='CM('3'); on each one. It would be helpful if there was a better approach to managing this issue.

The textboxes are organized into three divs, each containing around 35 textboxes. Perhaps there is a method to streamline the process based on DIV, but I am unaware of it.

Any assistance or advice on this matter would be greatly appreciated.

<asp:TextBox ID="txtDC1_D" runat="server" CssClass="STD_desc160"   onchange="CM('3');"></asp:TextBox>
<asp:TextBox ID="txtDC1_C" runat="server" CssClass="STD_cur30"     onchange="CM('3');"></asp:TextBox>
<asp:TextBox ID="txtDC1_1" runat="server" CssClass="STD_value55"   onchange="CM('3');"></asp:TextBox>
<asp:TextBox ID="txtDC1_2" runat="server" cssClass="STD_value55"   onchange="CM('3');"></asp:TextBox>
<asp:TextBox ID="txtDC1_3" runat="server" cssClass="STD_value55"   onchange="CM('3');"></asp:TextBox>
<asp:TextBox ID="txtDC1_B" runat="server" CssClass="STD_bassis"    onchange="CM('3');"></asp:TextBox>
<br />
<asp:TextBox ID="txtDC2_D" runat="server" CssClass="STD_desc160"   onchange="CM('2');"></asp:TextBox>
<asp:TextBox ID="txtDC2_C" runat="server" CssClass="STD_cur30"     onchange="CM('2');"></asp:TextBox>
<asp:TextBox ID="txtDC2_1" runat="server" CssClass="STD_value55"   onchange="CM('2');" ></asp:TextBox>
<asp:TextBox ID="txtDC2_2" runat="server" cssClass="STD_value55"   onchange="CM('2');" ></asp:TextBox>
<asp:TextBox ID="txtDC2_3" runat="server" cssClass="STD_value55"   onchange="CM('2');" ></asp:TextBox>
<asp:TextBox ID="txtDC2_B" runat="server" CssClass="STD_bassis"    onchange="CM('2');"></asp:TextBox>
<br />

Answer №1

For those considering jQuery as a solution (which I highly suggest), here is the code snippet:

$(function (){

    $("input[type=text]").on('change',function (){
     if ($(this).val()) $(this).val('Y'); else $(this).val('');
    })
});

If not, then unfortunately I will have to remove this response.

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

Every time I navigate to a new page in NextJs, the useEffect hook

I am working on developing a new blog app with Next.js. In the current layout of the blog, I have successfully fetched data for my sidebar (to display "recent posts") using the useEffect/fetch method, as getInitialProps only works on Pages. However, this ...

Tips for bypassing an argument using the POST method in NodeJS

Hey there! I started off by creating a question about passing over data using the GET method, but now I'm facing a new problem when trying to pass over data with the POST method. Below is my code snippet where things seem to be going wrong. My goal is ...

What is the process of emphasizing a WebElement in WebdriverIO?

Is there a way to highlight web elements that need to be interacted with or asserted in webdriverIO? Or is there a JavaScript code similar to the javascript executor in Selenium that can be used for this purpose? ...

Key within square brackets in a JSON array

I am dealing with a JSON array that includes a square bracket in the key, like this: { "msg":"OK", "data":[ { "nls!type":"NCR", "current":"Assign", "physicalid":"0FFE0001000009FC5BD6805C00001352", "attribute[custTitle]":"Tit ...

Determining the correctness of a radio group tick pattern using jQuery

I am working on a form that has 3 questions with radio groups. The goal is to show a hidden div after all 3 radio boxes are checked. The condition for the div to appear is if the first question is answered "NO" and the remaining 2 questions are answered ...

Error encountered with Open Graph tags on Nuxt.js (production environment?)

I recently incorporated OpenGraph tags into my Nuxt.js application by following the guidelines outlined in their SEO documentation available at https://nuxtjs.org/examples/seo-twitter-og The tags are being set from a child component using the SocialHead c ...

What steps should I follow to enable my bot to generate or duplicate a new voice channel?

I needed my bot to either create a new voice server or clone an existing one. The variable "voic" contains the ID of the voice channel. voic.voiceChannel.clone(undefined, true, false, 'Needed a clone') // example from ...

Using JavaScript ES6, we can access a specific array nested within a JSON array and loop through its elements by utilizing the

I have retrieved a JSON data from this link "response": [{ "id": "1", "title": "Star Wars", "project": [ "Star Wars Proj1", "Star Wars Proj2", "Star Wars Proj3", "Star Wars Proj4" ] }, { "id": "2", "titl ...

Implementing code to scroll and play multiple videos simultaneously using JavaScript and jQuery

This solution currently only works for one video, but it needs to be able to handle multiple videos (TWO OR MORE) <html> <head> <script src="https://code.jquery.com/jquery-1.8.0.min.js" integrity="sha256-jFdOCgY5bfpwZLi ...

Classify database information according to certain characteristics

My goal is to categorize and organize data retrieved from a database based on an ID. Here's how the initial list looks: Suppose list A is structured as follows: Id: Description: Status: 1 Desc1 1 2 Desc2 2 1 Desc3 2 3 D ...

Changing the data request body in datatables ajax on button click

My goal is to initially fetch data when the page loads and then allow users to apply filters by clicking on them to fetch updated data. The query I am using is a POST request because it requires complex parameters that need to be formatted as JSON for bett ...

Unexpectedly, the CommandInteraction feature came to a halt within Discord.js slashcommands

I was having no issues with this code, but now it's throwing an error: const {Client, CommandInteraction, MessageEmbed, Permissions} = require("discord.js"); module.exports = { name : 'ban', description : "bans the tar ...

What is the best way to receive live data in a node server in order to populate a rickshaw chart?

I currently have a rickshaw line chart configured in my html script like this: var data = []; var graph = new Rickshaw.Graph( { element: document.querySelector("#chart"), width: 1000, height: 100, renderer: 'line', series ...

Unable to establish connection through MQTT 1884 protocol

Currently, my website's messaging system is powered by MQTT. While everything is functioning smoothly on my local machine, I encounter an error when trying to use the system on the production site: vendor.bbaf8c4….bundle.js:1 WebSocket connection ...

What is the best way to save and retain cache data for an audio file?

I have a website where I am using an audio file in .swf format. This audio file can be turned on and off with the options provided: AUDIO ON and AUDIO OFF. However, I am facing the issue that the audio keeps playing repeatedly even after being turned off. ...

One way to retrieve API responses in node js is by utilizing callback functions

I am currently exploring callback functions and utilizing the request module in node js to retrieve information. As Javascript is asynchronous, I am struggling with how to properly return my response. Below are snippets of my code. In my app.js file: var ...

Verify the presence of blank space with javaScript

I currently have a text box on my website. <input type="text" name="FirstName" value="Mickey"> My goal is to prevent the user from entering empty spaces, tabs, or new lines in the text box. However, I want to allow spaces between characters. Does a ...

Incorporating JavaScript variables to enhance HTML attributes

Currently utilizing Backbone.js and in search of a solution to convert my data into hidden elements within a form for submission, as well as turning the data into values for textboxes. I am seeking a reliable solution that can effectively handle all speci ...

Utilizing Shared Models Across Nested ng-Change Controllers

Within my AngularJS application, I am faced with the challenge of utilizing a value from an input/dropdown field in the second controller when a change event occurs. The structure of my code is as follows: Code snippet (HTML) :: <body ng-app="myApp" ...

What is the best way to ensure that a Material UI transition component fully occupies the space of its parent component?

I've been experimenting with a Material UI transition component in an attempt to make it completely fill its parent container. So far, I've achieved some success by setting the width and height to 100% and applying a Y-axis translation for the co ...