javascript - Add select dropdown to table column with JS -
i have created table in html (4 rows , 3 columns). want add select dropdown in second column. unable add in column.
my code is:
<!doctype html> <html> <body> <table border="1" style="width:100%"> <tr> <th>criteria</th> <th>yes/no</th> <th>comments</th> </tr> <script> var array1 = [1,2,3,4]; for(var i=0; i<array1.length; i++) { document.write("<tr>"); document.write("<td>"+array1[i]+"</td>"); document.write("<td> </td>"); document.write("<td> </td>"); document.write("</tr>"); } </script> </table> </body> </html>
and select dropdown html is:
<select name="mydropdown"> <option value="milk">fresh milk</option> <option value="cheese">old cheese</option> <option value="bread">hot bread</option> </select>
this may
<!doctype html> <html> <body> <table border="1" style="width:100%"> <tr> <th>criteria</th> <th>yes/no</th> <th>comments</th> </tr> <script> var array1 = [1, 2, 3, 4]; (var = 0; < array1.length; i++) { var dropdown = "<select name='mydropdown'>" + "<option value='milk'>yes</option>" + "<option value='cheese'>no</option>" + "</select>"; document.write("<tr>"); document.write("<td>" + array1[i] + "</td>"); document.write("<td>" + dropdown + "</td>"); document.write("<td> </td>"); document.write("</tr>"); } </script> </table> </body> </html>
Comments
Post a Comment