utilizing javascript to compare the data in a gridview with the value entered in a

I am looking to compare the values entered in my textbox with the existing values in a gridview. I have achieved this on the server side using the following function:

protected void isRecordAlreadyExist(TextBox txt_Value, int res)
{
    ds_main = new DataSet();
    paramArray = new string[3, 2];
    paramArray[0, 0] = "@KeyWinCountNumber";
    paramArray[0, 1] = txtkeyWinCount.Text.Trim();
    paramArray[1, 0] = "@ContractNumber";
    paramArray[1, 1] = txtContractNum.Text.Trim();
    paramArray[2, 0] = "`";
    obj = new DalLib();
    ds_main = obj.getDataSet("sp_tbl_Contract_MatchValues", paramArray);
    gvContract.DataSource = ds_main.Tables[res];
    if (ds_main.Tables[res].Rows.Count > 0)
    {
        mtvResult.ActiveViewIndex = 3;
        btnSubmit.Enabled = false;
    }
    else
    {
        btnSubmit.Enabled = true;
    }
}

protected void txtkeyWinCount_TextChanged(object sender, EventArgs e)
{
    if (!string.IsNullOrEmpty(txtkeyWinCount.Text))
    {
        isRecordAlreadyExist(txtkeyWinCount, 0);
    }
    else
    {
        mtvResult.ActiveViewIndex = -1;
    }
}

However, I would also like to compare the value from the textbox with the gridview data on the client side using JavaScript. How can I achieve this? Any assistance would be greatly appreciated.

Answer №1

This function searches for a specific value entered in a TextBox within a grid and returns true if found.

You can trigger this function on the onchange event of the TextBox using JavaScript.

function SearchTextInGrid()
{
    // Set initial flag to false
    var flag = false;
    
    // Get the text to search for from the TextBox
    var searchText = document.getElementById('txtSearch').value;
    
    // Get the grid element
    var gridElement = document.getElementById('gridTable');
    
    // Loop through each row of the grid starting from index 1 
    for (i = 1; i < gridElement.rows.length; i++)
    {
        // Get the current row
        var currentRow = gridElement.rows[i];
        
        // Check if the value in the first cell of the row matches the search text
        if (currentRow.cells[0].textContent.trim() === searchText)
        {
            flag = true;
            break; // Exit the loop once matching value is found
        }
    }
    
    return flag;
}

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

Finding the parent div in the handleChange function using React

I am facing a challenge with multiple dynamic divs, as their number depends on the filter selected by the visitor. This makes it impossible to use getElementById in this scenario. My goal is to modify the parent div's CSS when an input is checked. B ...

The resource being requested is missing the 'Access-Control-Allow-Origin' header - Issue with Pinterest OAuth implementation

While working on implementing OAuth for Pinterest, I successfully retrieved the access code. However, when attempting to perform a GET /v1/me/ request, I encountered an error in the Chrome console: XMLHttpRequest cannot load . No 'Access-Contro ...

Unable to update div CSS using button click functionality

I have been working on this HTML/CSS code and I am trying to change the style of a div using a JavaScript button click event so that the div becomes visible and clickable. However, despite my efforts, it doesn't seem to be working as expected. Whenev ...

Dropdown selection values were not set appropriately

I've been encountering an issue with setting the selected value in a drop-down list using the code below. The values are being split from a comma-separated string, but it's not functioning as intended. When I use string='text1,text2,text3,t ...

Creating a hover effect for a div in jQuery or CSS: Keeping the div visible even when hovered

I have two divs in my layout: one is titled "title" and the other is called "description". I successfully made the description div appear when hovering over the title div. You can see an example of this behavior in action on this fiddle Now, I want to cha ...

Issue encountered during compilation of JavaScript in Vue framework with Rollup

Struggling to compile my Vue scripts with rollup. The error I'm facing is [!] Error: 'openBlock' is not exported by node_modules/vue/dist/vue.runtime.esm.js, imported by src/js/components/TestButton.vue?vue&type=template&id=543aba3 ...

Managing errors with asynchronous operations through promises and the async module

I'm currently diving into the world of node.js, focusing on developing an API that interacts with mongodb. As I work on the apiRequest function, I realize that it needs to call two separate functions, each responsible for querying the database. Howev ...

Guide on configuring and executing AngularJS Protractor tests using Jenkins

I am encountering an error with the following configuration: ERROR registration capabilities Capabilities [{platform=WINDOWS, ensureCleanSession=true, browserName=internet explorer, version=}] does not match the current platform LINUX 18:17:05.892 INFO ...

Building a hierarchical tree structure using arrays and objects with Lodash Js

I am attempting to create a tree-like structure using Lodash for arrays and objects. I have two arrays, one for categories and the other for products, both with a common key. The goal is to organize them into a tree structure using string indexing. let ca ...

What is the best way to access the current webdriver instance using code?

Currently, I am in the process of creating an end-to-end test suite with Protractor. As Protractor is based on WebdriverJS, I am attempting to utilize some of its functionality. More specifically, my goal is to incorporate certain behaviors using Webdriv ...

Tips on keeping the width and height in proportion to a 16:9 aspect ratio across all screen sizes

I am trying to keep the height and width proportional to a 16:9 aspect ratio on any screen size. The problem I am encountering is: I have a video on my website that follows a 16:9 aspect ratio format, with a width of 1280 and a height of 720. I calculate ...

JavaScript HTML content manipulation

Why doesn't this code work? innerHTML cannot handle something so complex? <html> <head> <script type="text/javascript"> function addTable() { var html = "<table><tr><td><label for="na ...

To interact with a specific cell in a table using Protractor, simply click

I have a dataset containing various elements such as images, text, and numbers. I am struggling to click on a specific text within the dataset. As someone new to e2e testing with Protractor, any assistance would be greatly appreciated. I specifically need ...

What is the most effective way to exchange data among multiple React applications?

I am looking for a solution to securely share data among multiple applications, with some parts of the data being secure and others not. I have explored options like IndexedDB and localStorage, but they don't work in all browsers, especially in incogn ...

Save all user information annually from the date they first sign up

Greetings! I am facing an issue where every time a year is added, it gets inserted between the day and month in the date of entry for a user at our company. var yearOnCompany = moment(user.fecha_ingreso_empresa, "YYYYMMDD").fromNow(); var dateStart = mome ...

How can you prevent a draggable element from surpassing the bottom of the screen?

I'm dealing with an element that I want to make draggable only along the Y-axis. It needs to be able to go past the top of the screen, but I need to restrict it from going past the bottom of the screen. I recently came across the containment feature i ...

Utilizing production and development configuration files in Angular and JavaScript with Webpack

I'm currently working with Webpack and Angular, trying to find a way to inject/use variables based on whether it's in development or production mode. Although I have Webpack set up to detect the environment (prod or dev), I am facing an issue wi ...

Is the form being submitted with the href attribute?

Does this code ensure security? <form id="form-id"> <input type='text' name='name'> <input type='submit' value='Go' name='Go'/></form> <a href="#" onclick="docume ...

Tips to swap selections in a Select2 dropdown box

Is there a way to dynamically clear a Select2 option list and reload it with new data? Despite setting the data as suggested, it seems to only append the new data without clearing the existing options. $("#optioner").select2(); $("#doit").click(functio ...

Is it possible to perform advanced SQL-like queries on JSON data using JavaScript?

Lately, I've been faced with a challenge where I need to manipulate a JSON result using SQL commands like left joins, sum, and group by. Has anyone else come across this issue recently? I'm currently experimenting with the jsonsql JavaScript libr ...