how to loop through rows in an HTML table to find a specific value?

Happydevdays

I have the following sample html: https://jsfiddle.net/pgd8e46b/1/

What I'm trying to do is let the users click on a row from the "available_widgets" table and if it's not already in the "existing_widgets" table, add it and do other things.

I have the logic to grab the appropriate table and start the loop...

 var check_for_duplicates = function (row_id) {     
     var table = document.getElementById('existing_widgets');
     var rows = table.getElementsByTagName('td');
     for (var i = 0, len = rows.length; i < len; i++) {
         console.log(i);

     }
     console.log(rows);
     return true;
 }

but I don't know how to compare the ID field with the id that's passed in. I still have to write the logic that strips out the "row_" prefix from the id that's passed to the check_for_duplicates() method.

Any suggestions would be appreciated.

dfsq

You can simplify check_for_duplicates function if you use jQuery to find widget row by id:

$('#available_widgets').on('click', 'tr', function () {
    if (check_for_duplicates(this.id)) {
        return false;
    } else {
        alert('otherwise, do other stuff');
    }
});

var check_for_duplicates = function (row_id) {
    return !!$('#existing_widgets').find('#' + row_id.replace('row_', '')).length;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to find a specific Foreign Key of a table through T-SQL?

From Dev

How to loop through specific range of rows with Python csv reader?

From Dev

How to get HTML Table Cell Value through JQuery?

From Dev

How to display all rows in a MySQL table with a specific column value?

From Dev

How to loop through a table in Corona?

From Dev

javascript to loop through table rows with a classname

From Dev

Loop through table cells of a HTML table with a specific class name

From Dev

Loop through rows and count based on table name

From Dev

Jquery loop through table rows and get nth child value

From Dev

How to search through JSON objects to find a specific parameter value?

From Dev

Loop through all cells in all rows in a table

From Dev

How to loop over specific table rows

From Dev

How to loop until one specific value or request again through an input

From Dev

MySQL and PHP: Loop through table find value if it exists update if not insert new value

From Dev

How to display all rows in a MySQL table with a specific column value?

From Dev

How to loop through HTML rows and change the background if conditions are met in JavaScript

From Dev

Find rows in SQL table that have specific part of value columns

From Dev

How to retrieve related child rows as I loop through rows from the parent table?

From Dev

How to change cell value of an html table through javascript

From Dev

How to loop through javascript object and display value in html

From Dev

how to use WHERE condition to find specific value from string in table?

From Dev

Jquery loop through table rows and get nth child value

From Dev

Loop through rows until you find a variable and then count the number of rows

From Dev

how to process json data through an .each loop into html table

From Dev

How to search through JSON objects to find a specific parameter value?

From Dev

How to loop through keys in a dict to find the corresponding value?

From Dev

Find HTML table rows containing input value

From Dev

loop through specific columns in table of excel

From Dev

Loop through a table to find specific id's

Related Related

  1. 1

    How to find a specific Foreign Key of a table through T-SQL?

  2. 2

    How to loop through specific range of rows with Python csv reader?

  3. 3

    How to get HTML Table Cell Value through JQuery?

  4. 4

    How to display all rows in a MySQL table with a specific column value?

  5. 5

    How to loop through a table in Corona?

  6. 6

    javascript to loop through table rows with a classname

  7. 7

    Loop through table cells of a HTML table with a specific class name

  8. 8

    Loop through rows and count based on table name

  9. 9

    Jquery loop through table rows and get nth child value

  10. 10

    How to search through JSON objects to find a specific parameter value?

  11. 11

    Loop through all cells in all rows in a table

  12. 12

    How to loop over specific table rows

  13. 13

    How to loop until one specific value or request again through an input

  14. 14

    MySQL and PHP: Loop through table find value if it exists update if not insert new value

  15. 15

    How to display all rows in a MySQL table with a specific column value?

  16. 16

    How to loop through HTML rows and change the background if conditions are met in JavaScript

  17. 17

    Find rows in SQL table that have specific part of value columns

  18. 18

    How to retrieve related child rows as I loop through rows from the parent table?

  19. 19

    How to change cell value of an html table through javascript

  20. 20

    How to loop through javascript object and display value in html

  21. 21

    how to use WHERE condition to find specific value from string in table?

  22. 22

    Jquery loop through table rows and get nth child value

  23. 23

    Loop through rows until you find a variable and then count the number of rows

  24. 24

    how to process json data through an .each loop into html table

  25. 25

    How to search through JSON objects to find a specific parameter value?

  26. 26

    How to loop through keys in a dict to find the corresponding value?

  27. 27

    Find HTML table rows containing input value

  28. 28

    loop through specific columns in table of excel

  29. 29

    Loop through a table to find specific id's

HotTag

Archive