填充使用下拉列表中的字段

问题描述 投票:0回答:1

我有一个由MySQL数据库使用下面的代码填充的下拉列表

<?php

                    $conn = new mysqli('localhost', 'root', '@', '')
                    or die ('Cannot connect to db');

                    $result = $conn->query("select name, surname FROM clients");
                    echo "<html>";
                    echo "<body>";
                    echo "<select name='client_name' id='client'>";

                    while ($row = $result->fetch_assoc()) {

                        unset($msisdn, $contract_type, $provider);
                        $name = $row['name'];
                        $surname = $row['surname'];
                        echo '<option value="'.$name.'_'.$surname.'">'.$name.' '.$surname.'</option>';
                    }
                    echo "</select>";
                    echo "</body>";
                    echo "</html>";
                    ?>

我想填充在下拉列表与结果相关信息的不同领域。

<input type="text" name="address">
<input type="text" name="tel">
<input type="text" name="id_nr">

$('#client').change(function() {
    selectedOption = $('option:selected', this);
    $('input[name=address]').val( selectedOption.data('address') );
    $('input[name=tel]').val( selectedOption.data('tel') );
    $('input[name=id_nr]').val( selectedOption.data('id_nr') );
});
php html mysql
1个回答
0
投票

你应该数据集选择,因为

echo '<option data-address-"'.$address.'" value="'.$name.'_'.$surname.'">'.$name.' '.$surname.'</option>';

此外,更新您的查询与姓名相处地址。

© www.soinside.com 2019 - 2024. All rights reserved.