Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 04/11/2023 in all areas

  1. That code is doing things the hard way. HTML has a template tag for a reason. Use your PHP code to generate a template row in a template tag. The your JS only needs to clone that row and add it to the table. For example: Template: <template id="row-template"> <tr> <td></td> <td> <select class="background" name="Department[]"> <option value="">Department</option> <?php $qry = mysqli_query($conn,"SELECT DISTINCT Brand FROM model ORDER BY Brand ASC"); while($row = $qry->fetch_assoc()) { echo "<option"; if(isset($_REQUEST['Department']) and $_REQUEST['Department']==$row['Brand']) echo ' selected="selected"'; echo ">{$row['Brand']}</option>\n"; } ?> </select> </td> <td><input type='text' name='category[]'></td> <td><input type='text' name='sub_category[]'></td> <td><input type='text' name='model[]'></td> <td><input type='number' name='qty[]'></td> </tr> </template> JS: const template=document.getElementById('row-template'); const tbody=document.getElementById('tbody'); let itemCount=0; function addItem(){ const newRow = template.content.cloneNode(true); const firstTd = newRow.querySelector('td:first-child'); firstTd.textContent=++itemCount; tbody.appendChild(newRow); }
    1 point
This leaderboard is set to New York/GMT-04:00
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.