Форум программистов, компьютерный форум, киберфорум
jQuery
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
0 / 0 / 0
Регистрация: 29.03.2011
Сообщений: 6
1

Как тут добавить поля в форму?

29.03.2011, 17:44. Показов 1312. Ответов 0
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Нашел форму выборки города. Никак не соображу как вставить сюда ещё пару таких же полей, по такому же принципу, как тут - страна-область-город.
Пытался всё повторить, как тут в обоих файлах, но видимо, что-то недосмотрел, может с закрывающими скобками запутался или вообще не то делал .
Далее нужны поля, допустим, фрукты-яблоко.
Кто силен в этих вещах? Помогите, пожалуйста!
Вот первый оригинальный код:
HTML5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
        <script language="javascript" src="http://cite/jquery/jquery-1.4.2.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
                $.post("http://cite/cities.php", {},
                    function (xml) {
                        $(xml).find('country').each(function() {
                            id = $(this).find('id_country').text();
                            $("#country").append("<option value='" + id + "'>" + $(this).find('country_name_ru').text() + "</option>");
                    });
                });
                $("#country").change(function() {
                    id_country = $("#country option:selected").val();
                    if (id_country == "") {
                        $(".region, .city, .submit").hide();
                    }else {
                        $("#region").html('');
                        $("#region").html('<option value="">Выберите регион</option>');
                        $.post("http://cite/cities.php", {id_country: id_country},
                            function (xml) {
                                $(xml).find('region').each(function() {
                                id = $(this).find('id_region').text();
                                $("#region").append("<option value='" + id + "'>" + $(this).find('region_name_ru').text() + "</option>");
                            });
                        });
                        $(".region").show();
                    }
                });
                $("#region").change(function() {
                    id_region = $("#region option:selected").val();
                    if (id_region == "") {
                        $(".city").hide();
                    }else {
                        $("#city").html('');
                        $("#city").html('<option value="">Выберите город</option>');
                        $.post("http://cite/cities.php", {id_region: id_region},
                            function (xml) {
                                $(xml).find('city').each(function() {
                                id = $(this).find('id_city').text();
                                $("#city").append("<option value='" + id + "'>" + $(this).find('city_name_ru').text() + "</option>");
                            });
                        });
                    }
                    $(".city").show();
                });
                $("#city").change(function() {
                    if ($("#city option:selected").val() == "") {
                        $(".submit").hide();
                    }else {
                        $(".submit").show();
                    }
                });                
            });
        </script>
 
      <body>
     
        <form action="http://cite/autodrom" method="POST" enctype="multipart/form-data">
            <div>
                <strong>Страна:</strong>
                <select name="country" id="country">
                <option value="" selected>Выберите страну</option>
                </select>
            </div>
            <div class="region">
                <strong>Регион:</strong>
                <select name="region" id="region">
                <option value="">Выберите регион</option>
                </select>
            </div>
            <div class="city">
                <strong>Городишко:</strong>
                <select name="city" id="city">
                <option value="">Выберите город</option>
                </select>
     </div>
                    
            <div>
            <input type="submit" class="submit" value="Сохранить">
            </div>
        </form>  
 </body>
Вот обработчик:
PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
header('Content-type: text/xml; charset=windows-1251');
 
$db_host = 'localhost';
$db_user = 'user';
$db_pass = 'pass';
$db_name = 'base';
 
$cities = new cities($db_host, $db_user, $db_pass, $db_name);
if (isset($_POST['id_country'])) {
    $cities->get_regions($_POST['id_country']);
}elseif (isset($_POST['id_region'])) {
    $cities->get_cities($_POST['id_region']);
}
else {
    $cities->get_countries();
}
 
class cities {
    private $db;
    public $xml = '<?xml version="1.0" encoding="windows-1251"?><root>';
    
    function __construct($db_host, $db_user, $db_pass, $db_name) {
        $this->db = mysql_connect($db_host, $db_user, $db_pass);
        mysql_select_db($db_name, $this->db);       
    }
    
    function get_countries() {
        $mysql_result = mysql_query("SELECT * FROM countries ORDER BY country_order", $this->db);
        while($country = mysql_fetch_assoc($mysql_result)) {
            $this->xml .= '<country>';
            $this->xml .= '<id_country>'.$country['id_country'].'</id_country>';
            $this->xml .= '<country_name_ru><![CDATA['.$country['country_name_ru'].']]></country_name_ru>';
            $this->xml .= '<country_name_en><![CDATA['.$country['country_name_en'].']]></country_name_en>';
            $this->xml .= '<iso>'.$country['country_iso'].'</iso>';
            $this->xml .= '</country>';
        }
        $this->print_xml();
    }
    
    function get_regions($id_country) {
        $mysql_result = mysql_query("SELECT * FROM regions WHERE id_country = ".intval($id_country)." ORDER BY region_order", $this->db);
        while($region = mysql_fetch_assoc($mysql_result)) {
            $this->xml .= '<region>';
            $this->xml .= '<id_region>'.$region['id_region'].'</id_region>';
            $this->xml .= '<region_name_ru><![CDATA['.$region['region_name_ru'].']]></region_name_ru>';
            $this->xml .= '<region_name_en><![CDATA['.$region['region_name_en'].']]></region_name_en>';
            $this->xml .= '</region>';
        }
        $this->print_xml();
    }
    
    function get_cities($id_region) {
        $mysql_result = mysql_query("SELECT * FROM cities WHERE id_region = ".intval($id_region)." ORDER BY city_order", $this->db);
        while($city = mysql_fetch_assoc($mysql_result)) {
            $this->xml .= '<city>';
            $this->xml .= '<id_city>'.$city['id_city'].'</id_city>';
            $this->xml .= '<city_name_ru><![CDATA['.$city['city_name_ru'].']]></city_name_ru>';
            $this->xml .= '<city_name_en><![CDATA['.$city['city_name_en'].']]></city_name_en>';
            $this->xml .= '</city>';
        }
        $this->print_xml();
    }
    
    function print_xml() {
        $this->xml .= '</root>';
        echo $this->xml;
    }
}
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
29.03.2011, 17:44
Ответы с готовыми решениями:

Как добавить поля в форму
Необходимо добавить расчетные поля в подчиненную форму. То есть,нужно Добавить поле...

Как в форму добавить поля только что созданной таблицы?
Отредактировал форму, создал новую таблицу, но не получается добавить в форму поля недавно...

Добавить данные поля из таблицы в форму
Доброго времени суток. У меня вопрос простой, но так как только разбираюсь с программированием не...

Добавить в форму поля со второй таблицы
Господа программисты, и снова здравствуйте! Только учусь. Как в форму вставить поля с таблицы...

0
29.03.2011, 17:44
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
29.03.2011, 17:44
Помогаю со студенческими работами здесь

Добавить значение через форму из поля в список
Народ привет! Суть задачи такова. Имеется две таблицы и две формы для внесения значений в эти...

как проверить поля форму занять или нет до отправки форму
как проверить поля форму занять или нет до отправки форму как через ajax проверить ...

Как добавить запись в подчиненную форму через форму элемента?
Есть основная форма. На ней подчиненная табличная форма - список короче. Отдельно есть форма для...

Можно ли как нибудь добавить данные из 1 поля 1 таблицы в pickllist другого поля другой таблицы?
Добавить данные в picklist полю ФИО, чтоб получился выпадающий список Бред конечно, ноо... Может...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
1
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru