Имеется форма регистрации: HTML: <div id=reg> <form action=reg_result.php method=post id=registration> <table cellspacing=10 style=width:100%;> <tr> <td colspan=2 style=font-size:30px;font-weight:500;>Регистрация:</td> </tr> <tr> <td>Логин:</td> <td class=nb> <input type=text name=login id=login class=required title='Выберите себе логин'></td> </tr> <tr> <td>E-mail:</td> <td class=nb> <input type=text name=email id=email></td> </tr> <tr> <td>Повторите E-mail:</td> <td class=nb> <input type=text name=email2 id=email2></td> </tr> <tr> <td>Пароль:</td> <td class=nb> <input type=password name=pass id=pass></td> </tr> <tr> <td>Повторите пароль:</td> <td class=nb> <input type=password name=repass id=repass></td> </tr> <tr> [b] <td>Страна:</td> <td class=nb> <select name=country lang=20 id=country> </select> </td>[/b] </tr> <tr> [b] <td>Область:</td> <td class=nb> <select name=obl lang=20 id=obl> </select> </td>[/b] </tr> <tr> [b] <td>Город:</td> <td class=nb> <select name=town lang=20 id=town> </select> </td>[/b] </tr> <tr> <td>Дата Рождения(формат: дд/мм/гггг):</td> <td class=nb> <input type=text name=birthday id=birthday></td> </tr> <tr></tr> <tr> <td colspan=3 align=right class=nb><input type=submit name=submit value=Регистрация id=submit> </td> </tr></div> </table></form> Есть три таблицы: 1)country: +------------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+------------------+------+-----+---------+----------------+ | country_id | int(11) unsigned | NO | PRI | NULL | auto_increment | | city_id | int(11) | NO | MUL | 0 | | | name | varchar(128) | NO | | | | +------------+------------------+------+-----+---------+----------------+ 2)region: +------------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+------------------+------+-----+---------+----------------+ | region_id | int(10) unsigned | NO | PRI | NULL | auto_increment | | country_id | int(10) unsigned | NO | MUL | 0 | | | city_id | int(10) unsigned | NO | MUL | 0 | | | name | varchar(64) | NO | | | | +------------+------------------+------+-----+---------+----------------+ 3)city: +------------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+------------------+------+-----+---------+----------------+ | city_id | int(11) unsigned | NO | PRI | NULL | auto_increment | | country_id | int(11) unsigned | NO | MUL | 0 | | | region_id | int(10) unsigned | NO | MUL | 0 | | | name | varchar(128) | NO | | | | +------------+------------------+------+-----+---------+----------------+ Нужно организовать аякс запрос, чтобы при выборе страны в поле селект для области добалялись все области этой страны из таблицы region,а при выборе области добавлялись в соответствующее поле города этой области.
Огромное спасибо за ссылку) Но все арвно проблемы:почему-то выводит значения:null [js]$(document).ready(function () { $('#country').change(function () { var country = $(this).val(); if (country == '0') { $('#obl').html(''); $('#obl').attr('disabled', true); return(false); } $('#obl').attr('disabled', true); $('#obl').html('<option>çàãðóçêà...</option>'); var url = 'get_regions.php'; $.get( url, "country=" + country, function (result) { var options = ''; $(result.regions).each(function() { options += '<option value="' + $(this).attr('region_id') + '">' + $(this).attr('title') + '</option>'; }); $('#obl').html(options); $('#obl').attr('disabled', false); }, "json" ); }); });[/js] PHP: <td>Ñòðàíà:</td> <td class=nb> <select name=country id=country> <option value='choose' SELECTED>Ñòðàíà ïðîæèâàíèÿ</option> "; $conn=db_connect(); $strany=$conn->query("select * from country"); $num=$strany->num_rows; for ($i=0;$i<$num;$i++) { $row=$strany->fetch_assoc(); echo" <option value=".$row['country_id'].">".$row['name']."</option>"; } echo" </select> </td> </tr> <tr> <td>Îáëàñòü:</td> <td class=nb> <select name=obl lang=20 id=obl DISABLED> </select> </td> </tr> PHP: <?php include('functions.php'); sleep(rand(1,3)); $country_id = @intval($_GET['country']); $regions = array(); $conn=db_connect(); $res=$conn->query("select * from region where country_id='".$country_id."'"); $num=$res->num_rows; for($i=1;$i<=$num;$i++){ $regs1 = $res->fetch_assoc(); $regs=$regs1['name']; $regions[] = array('id'=>$regs1['region_id'], 'title'=>trim($regs)); } $result = array('type'=>'success', 'regions'=>$regions); print json_encode($result) ?> Кому несложно, укажите где ошибка.