<html> <head> <title></title> <script src='../js/jquery.js' type='text/javascript'></script> <script type="text/javascript"> $(document).ready(function(){ showCountriesById($('#countryId').val()); }); function showCountriesById (val) { $.ajax({ type: "POST", url: "ajax.php", data: "countryId="+val, success: function(html){ $("#cityContainer").html(html); } }); } </script> </head> <body> <select name="countryId" id="countryId" onchange="showCountriesById(this.value)"> <?php //Выводишь страны if (isset( $countryArr)) { ?> <?php foreach ( $countryArr as $s) { ?> <option value="<?=$s['id']?>"><?=$s['strana']?></option> <?php } ?> <?php } ?> </select> <div id="cityContainer"> </div> </body> </html>
<?php $countryId = $_POST['countryId']; //Выбираешь из бд города и заносишь в массив $html .= '<select name="cities">'; while ($row = mysql_fetch_array($res)) { $html .= '<option value="'.$row['id'].'" >'.$row['gorod']'.</option>'; } echo $html; ?>