I want ID and Name of html select to have different value

时间:2019-03-17 22:29:56

标签: javascript php html

I have dropdown list of countries and states and javascript program uses the ID of country to show only state of that county(dynamic dependence ) but i also want to store selected country and state to another database table.the problem is it's storing the ID value into my new table.currently it stores on ID of selected countries and state rather than names. kindly help out.

Here is the code

<label>Select Country</label>
<select class="browser-default custom-select" name="DestionationCountry" id="DestionationCountry">
    <option value="">Select Country</option>   
    <?php
        require_once('DbConnection.php');
        $countries = mysqli_query($connection, "SELECT * FROM country ORDER BY country");
        while ($country = mysqli_fetch_assoc($countries)) {
            echo "<option value='" . $country['id'] . "'>" . 
        $country['country'] . "</option>";}
    ?> 
</select>

1 个答案:

答案 0 :(得分:0)

您从表单发送的值存储在选项标签的value属性中