gpt-4-0314· OpenAI
WildChat-4.8M (AI2)
you are a senior web developer, give me an example of how to filter html table based on…
- User
you are a senior web developer, give me an example of how to filter html table based on entered multiple id matching the index column
- Assistant
To filter an HTML table based on multiple IDs matching the index column, you can utilize JavaScript and some event handlers to do that. Here's an example:
HTML:
<!DOCTYPE html> <html> <head> <style> input[type=text] { width: 100%; padding: 12px 20px; margin: 8px 0; box-sizing: border-box; } </style> </head> <body> <input type="text" id="searchInput" onkeyup="filterTable()" placeholder="Search for IDs (comma separated)..."> <table id="myTable"> <thead> <tr> <th>ID</th> <th>Name</th> <th>Email</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>John Doe</td> <td>john.doe@example.com</td> </tr> <tr> <td>2</td> <td>Jane Doe</td> <td>jane.doe@example.com</td> </tr> <tr> <td>3</td> <td>Mark Smith</td> <td>mark.smith@example.com</td> </tr> </tbody> </table> <script> function filterTable() { var input, filterList, table, tr, td, i, txtValue; input = document.getElementById("searchInput"); filterList = input.value.split(',').map(id => id.trim()); table = document.getElementById("myTable"); tr = table.getElementsByTagName("tr"); for (i = 0; i < tr.length; i++) { td = tr[i].getElementsByTagName("td")[0]; if (td) { txtValue = td.textContent || td.innerText; if (filterList.includes(txtValue)) { tr[i].style.display = ""; } else { tr[i].style.display = "none"; } } } } </script> </body> </html>
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.