I have the following Jquery function:
$( document ).ready(function() {
$(function() {
$('select[name="CPUmenu"]').change(function(e) {
let socket = $(this).val();
$('tbody tr[data-socket]').show();
if (socket.length) {
$('tbody tr[data-socket!="' + socket + '"]').hide();
}
});
});
});
Other code:
CPUmenu:
$sql = "SELECT name, socket FROM cpu";
$result = $connection->query($sql);
if ($result->num_rows > 0) {
echo "<select name='CPUmenu'>";
echo "<option value=''>CPU</option>";
// output data of each row
while($row = $result->fetch_assoc()) {
if ($row["name"] == $namehref) {
echo "<option value='". $row["socket"] . "' selected>".$row["name"]."</option>";
} else {
echo "<option value='". $row["socket"] . "'>".$row["name"]."</option>";
}
}
echo "</select>";
} else {
echo "0 results";
}
myTable:
$sql = "SELECT name, price, id, socket, ramslots, maxram, chipset FROM motherboard";
$result = $connection->query($sql);
if ($result->num_rows > 0) {
echo "<table id='myTable'><thead><tr><th>Motherboard</th><th>Price</th><th>Socket</th><th>Chipset</th><th>Ram Slots</th><th>Max Ram</th></tr></thead>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tbody><tr data-socket='". $row['socket'] . "'><td><a href='https://au.pcpartpicker.com/product/" . $row["id"] . "' target='_blank'>" . $row["name"] . "</a></td><td>" . $row["price"] . "</td><td>" . $row["socket"] . "</td><td>" . $row["chipset"] . "</td><td>" . $row["ramslots"] . "</td><td>" . $row["maxram"] . "</td></tr></tbody>";
}
echo "</table>";
} else {
echo "0 results";
}
I just tried this but no it doesn't work at all
However it only runs whenever i select a new option in "CPUmenu", I would like it to also run once when the page is opened and loaded.
Thanks