Top Ad unit 728 × 90

Find Duplicates in HTML Table

If someone uses dataTable plugin, can use the following method to find out the duplicate records while adding new record or you can try this code before saving the data
function findInTable(str, tableID){
         $('#' + tableID + ' tr').each(function(){
                 $(this).children('td').each(function(){
                       if ( $(this).html() == str ){
                               alert('Duplicate Records found. ');
                               return false;
                       }
                 }); //end of td each...
         }); //end of tr each...
} //end of function..
 findInTable('your_text', 'put_your_table_id'); // <table id="put_your_table_id">...</table>

Call this function where you want to apply and enjoy!

You can use a tag as boolean datatype to prevent adding duplicate record means if it found the data that already exists in the table then it shows a message that "Duplicate Records Can Not Be Inserted." otherwise it would add a new record into the table.


Example: In below example I have written the code directly without using a function and it works fine.



            var dup = false;
            $('#TableId tr').each(function(e){
                   $(this).children('td').each(function(){
                           if ( $(this).html() == $('#textbox').val() ){
                                 alert('
Duplicate Records Can Not Be Inserted.');
                                 dup = true;
                                 return false;
                           }
                     }); 

            });  //end dup checking
            

            if(dup === false){
                      //Execute your code here
            }//end of duplicate checking...
Try this code if you get any issue just feel free to comment here or if you have good example for this code then just write here for helping the people. thanks!
Find Duplicates in HTML Table Reviewed by Ashok Sen on 13:35:00 Rating: 5

No comments:

Website Design Company at Kolkata All Rights Reserved © 2014 - 2019
Developed by Asenwebmedia

Contact Form

Name

Email *

Message *

Powered by Blogger.