you are a senior full stack web developer, show me an example of click a button to pop a…
- User
you are a senior full stack web developer, show me an example of click a button to pop a textbox and enter multiple lines of ID to filter out table rows matching the first column
- Assistant
Here's an example using HTML, JavaScript, and a little bit of CSS. This code creates a button that, when clicked, will show a multi-line text box for entering IDs. Then, when the filter button is clicked, the table rows will be filtered based on the IDs entered, matching the content of the first column:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Filter Table by ID</title> <style> textarea { display: none; } </style> </head> <body> <button id="showTextareaBtn">Click to enter IDs</button> <textarea id="idTextarea" rows="6" cols="20"></textarea> <button id="filterBtn" onclick="filterTable()">Filter</button> <table id="dataTbl" border="1"> <tr> <th>ID</th> <th>Name</th> </tr> <tr> <td>101</td> <td>John</td> </tr> <tr> <td>102</td> <td>Alice</td> </tr> <tr> <td>103</td> <td>Mike</td> </tr> <tr> <td>104</td> <td>Emma</td> </tr> </table> <script> document.getElementById("showTextareaBtn").addEventListener("click", function() { document.getElementById("idTextarea").style.display = "block"; }); function filterTable() { const input = document.getElementById("idTextarea"); const ids = input.value.split("\n").map(id => id.trim()); const table = document.getElementById("dataTbl"); const rows = table.getElementsByTagName("tr"); for (let i = 1; i < rows.length; i++) { const firstCol = rows[i].getElementsByTagName("td")[0]; if (ids.includes(firstCol.textContent)) { rows[i].style.display = ""; } else { rows[i].style.display = "none"; } } } </script> </body> </html> - User
thanks, modify the code to this: two buttons in the same rows, the textarea should be in next row after 'Click to enter IDs' button was clicked, change button text to 'Hide Textbox'
- Assistant
Here's the updated code according to your requirements:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Filter Table by ID</title> <style> textarea { display: none; } </style> </head> <body> <div> <button id="toggleTextareaBtn">Click to enter IDs</button> <button id="filterBtn" onclick="filterTable()">Filter</button> </div> <textarea id="idTextarea" rows="6" cols="20"></textarea> <table id="dataTbl" border="1"> <tr> <th>ID</th> <th>Name</th> </tr> <tr> <td>101</td> <td>John</td> </tr> <tr> <td>102</td> <td>Alice</td> </tr> <tr> <td>103</td> <td>Mike</td> </tr> <tr> <td>104</td> <td>Emma</td> </tr> </table> <script> const toggleTextareaBtn = document.getElementById("toggleTextareaBtn"); const idTextarea = document.getElementById("idTextarea"); toggleTextareaBtn.addEventListener("click", function() { if (idTextarea.style.display === "none") { idTextarea.style.display = "block"; toggleTextareaBtn.textContent = "Hide Textbox"; } else { idTextarea.style.display = "none"; toggleTextareaBtn.textContent = "Click to enter IDs"; } }); function filterTable() { const input = idTextarea; const ids = input.value.split("\n").map(id => id.trim()); const table = document.getElementById("dataTbl"); const rows = table.getElementsByTagName("tr"); for (let i = 1; i < rows.length; i++) { const firstCol = rows[i].getElementsByTagName("td")[0]; if (ids.includes(firstCol.textContent)) { rows[i].style.display = ""; } else { rows[i].style.display = "none"; } } } </script> </body> </html> - User
maybe try use element, click the button to show a textbox input form in the right bottom corner, the form should contains a title text "Enter IDs below" and a submit and close button
- Assistant
Here's the updated code with a form displayed in the right bottom corner containing a title, multi-line text area, and "Submit" and "Close" buttons: