<script> function selectKat2(){ var kat1 = $('select[name="kat1"]').val(); if(!kat1){ $('div[name="selectDataKat2"]').html(''); $('div[name="selectDataKat3"]').html(''); $('div[name="selectDataKat4"]').html(''); }else{ $.ajax({ type: "POST", url: "ajax.php", data: { action: 'showKat2ForInsert', kat1: kat1 }, cache: false, success: function(responce){ $('div[name="selectDataKat2"]').html(responce); } }); }; }; function selectKat3(){ var Kat2 = $('select[name="kat2"]').val(); $.ajax({ type: "POST", url: "ajax.php", data: { action: 'showKat3ForInsert', kat2: kat2 }, cache: false, success: function(responce){ $('div[name="selectDataKat3"]').html(responce); } }); }; function selectKat4(){ var Kat3 = $('select[name="kat3"]').val(); $.ajax({ type: "POST", url: "ajax.php", data: { action: 'showKat4ForInsert', kat3: kat3 }, cache: false, success: function(responce){ $('div[name="selectDataKat4"]').html(responce); } }); }; </script> <div id="ilanekle" class="ilanekle" <?php if( temizle($_GET['is'])=="openadd" ) { } else { echo "style='display:none'" ;} ?> > <form action="panel_elanlar_add.html" method="post" enctype="multipart/form-data" class="cmxform" id="ilanForm" onsubmit="return validate(this);"> <fieldset> <p> <dl> <dt><label for="kat1">Elan Növü Seçin:</label></dt> <dd> <select style="width:305px" name="kat1" onchange="javascript:selectKat2();" > <option value="" >Elan Növü</option> <?php $sql="SELECT * from kat1_elan order by kat_ad asc"; $sorgu=mysql_query($sql); while($sehircek=mysql_fetch_assoc($sorgu)) {?> <option value="<?php echo $sehircek['id']; ?>" <?php if($kat1==$sehircek['id']) { echo "selected='selected'"; } ?>> <?php echo $sehircek['kat_ad']; ?></option><?php }?> </select></dd> </dl> </p> <div name="selectDataKat2" style="float:left;"></div> <div name="selectDataKat3" style="float:left;"></div> <div name="selectDataKat4" style="float:left;"></div> //File ajax.php <?php ini_set(default_charset,"UTF-8"); # include data base require "../include/ayar.inc"; switch ($_POST['action']){ case "showKat2ForInsert": echo '<select size="1" name="kat2" onchange="javascript:selectKat3();">'; $rows = $DB->select('SELECT * FROM kat2_elan WHERE kat1=? ORDER BY kat2_name ASC', $_POST['kat1']); foreach ($rows as $numRow => $row) { echo '<option value="'.$row['kat1'].'">'.$row['kat2_name'].'</option>'; }; echo '</select>'; break; case "showKat3ForInsert": echo '<select size="1" name="kat3" onchange="javascript:selectKat4();">'; $rows = $DB->select('SELECT * FROM kat3_elan WHERE kat2=? ORDER BY kat3_name ASC', $_POST['kat2']); foreach ($rows as $numRow => $row) { echo '<option value="'.$row['id'].'">'.$row['kat3_name'].'</option>'; }; echo '</select>'; break; case "showKat4ForInsert": echo '<select size="1" name="kat4">'; $rows = $DB->select('SELECT * FROM kat4_elan WHERE kat3=? ORDER BY kat4_name ASC', $_POST['kat3']); foreach ($rows as $numRow => $row) { echo '<option value="'.$row['id'].'">'.$row['kat4_name'].'</option>'; }; echo '</select>'; break; }; ?> 
  • What does "Does not work correctly?" What errors occur? What should happen according to the idea, and what is not happening? - Al Mr
  • When selecting 1, select the second select where the ID of the first select is specified on the second, and when selecting the second, put 3 where the ID of the second select and when selecting 3 select also show 4. And if there is no one with subcategories, then that does not show as well When choosing the first select, there is nothing to remove - Alex
  • Read here - Stackoverflow.com/questions/691866/… - Petr Chalov

0