I have the following php page with four dropdown list correctly populated with four differents mysql query.
I would populate Categories_2 through a query depending on CATEGORIES_1.c_id and the same nested for others dropdown.
Tried to call myFunction() onChange but it seems not working. I don't get the alert.
Does anyone know how I could do this? Any help would be much appreciated.
I know I have to use mysqli but it's an existing page and I will do it later.
<script>
var myDropdown=document.getElementsByName('cat1')[0];
function myFunction(){
alert('option changed : '+myDropdown.value);
}
</script>
<form enctype="multipart/form-data" method="post" action="import.php">
<label for="cat_name">Categories_1</label>
<select name = "cat1" onChange="myFunction()">
<?php
$s = mysql_query("SELECT * FROM `CATEGORIES_1`");
while($row = mysql_fetch_assoc($s)) {
echo ('<option value="' . $row['c_id'] . '">' . $row['c_name'] . '</option>'); } ?>
</select>
<br>
<label for="cat_nam">Categories_2</label>
<select>
<?php
$s = mysql_query("SELECT c_name FROM `CATEGORIES_2`");
while($row = mysql_fetch_assoc($s)) {
echo ('<option value="0">' . $row['c_name'] . '</option>'); } ?>
</select>
<br>
<label for="cat_nae">Categories_3</label>
<select>
<?php
$s = mysql_query("SELECT c_name FROM `CATEGORIES_3`");
while($row = mysql_fetch_assoc($s)) {
echo ('<option value="0">' . $row['c_name'] . '</option>'); } ?>
</select>
<br>
<label for="cat_ame">Categories_4</label>
<select>
<?php
$s = mysql_query("SELECT c_name FROM `CATEGORIES_4`");
while($row = mysql_fetch_assoc($s)) {
echo ('<option value="0">' . $row['c_name'] . '</option>'); } ?>
</select>