I have been working on a table that consists of 5 or 6 td elements. The data in the table is derived from 3 dropdown menus along with a Go button. When I enter values in all three dropdowns and click on Go, it displays the result in the table. However, the issue arises when I do not select a value in one or two of the dropdowns and keep it as null. In such cases, I don't want that particular column to show up in the table. I've been attempting to achieve this using JavaScript but haven't been successful so far. Here's the HTML code snippet:
$(document).ready(function() {
$("#go").click(function() {
var select1 = document.getElementById("select1").value;
var select2 = document.getElementById("select2").value;
var select3 = document.getElementById("select3").value; // Note: There was an extra semicolon here
});
if (select1 == null) {
document.getElementByClass('select1td').style.display = none;
}
if (select2 == null) {
document.getElementByClass('select2td').style.display = none;
}
});
<select id="select1" name="select1" style="width: 190px; display: block;">
<option selected value="" disabled="disabled">Select an option</option>
<?php
$sql="SELECT DISTINCT name FROM tbl1 ";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
echo "<option class='name' value=' " . $row['name'] ."'>" . $row['name'] ."</option>";
}
?>
</select>
<label>Lot Name</label>
<select id="select2" name="select2" style="width: 190px; display: block;">
<option selected value="" disabled="disabled">Select an option</option>
<?php
$sql="SELECT DISTINCT course FROM tbl1 ";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
echo "<option class='course' value=' " . $row['course'] ."'>" . $row['course'] ."</option>";
}
?>
</select>
<!-- And there is also a third dropdown menu -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td class="select1td">
<?php echo $row["name"]; ?>
</td>
<td class="select2td">
<?php echo $row["course"]; ?>
</td>
<td class="select3td">
<?php echo $row["reg"]; ?>
</td>
</table>