Sidhant Kushwaha Sidhant Kushwaha - 5 months ago 13
Javascript Question

Display table rows with specific data providing data from javascript variable

Unable to provide data from javascript variable to search the given data in the table and display only that rows of html table.

Its working fine for the constant data embedded in the code but does't except variable data.

Also i wanted to have multiple variable combination to search for like the sql query

SELECT * FROM mytable WHERE name="Ram" OR age="12";




$("#datatable tbody tr").hide();
$("#datatable tr:contains('Ram')").show();
});

//I want to use something like this

var name='Ram';
$("#datatable tbody tr").hide();
$("#datatable tr:contains(name)").show();
});




Answer

It seems you have to pass the variable outside the quotes.

var name='Ram';
    $("#datatable tbody tr").hide();
$("#datatable tr:contains('"+name+"')").show(); //Changed here.Note the quotes
});
Comments