У меня большая дилемма, я генерирую данные из MySQL в форму, поэтому проблема в том, что, хотя первая строка, сгенерированная SQL, равна 0, опция выбора в форме интерпретирует первое значение как 1.
Не было бы никаких проблем, если бы я не хотел выбрасывать некоторые данные из этого запроса. Но вот код:
<select id="exp_address" name="exp_address" onChange="document.getElementById('exp_city').value = this.options[this.selectedIndex].getAttribute('data-exp_city'); document.getElementById('exp_dist').value = this.options[this.selectedIndex].getAttribute('data-exp_distr'); document.getElementById('exp_address_val').value = this.options[this.selectedIndex].getAttribute('data-exp_city_val')">
<?php
for($i = 0; $i < $expselnum; $i++){
$exps_add_id = mysql_result($expsel,$i,'address_id');
$exps_address = mysql_result($expsel,$i, "address");
$exps_city = mysql_result($expsel,$i, "city");
$exps_distr_val = mysql_result($expsel,$i, "district");
echo "<option value=$exps_add_id data-num=$i data-exp_city = '$exps_city' data-exp_distr = '$exps_distr_val' data_exp_city_val = '$exps_city'>$exps_address</option>";
}
?>
</select>
и вот сгенерированный HTML-код:
<select onChange="Here is some JS to change the value of District and City inputs">
<option value=1 data-num=0 data-exp_city = 'BUCURESTI' data-exp_distr = 'Bucuresti' data_exp_city_val = 'BUCURESTI' [selected by default]>Another Address in RO</option><option value=2 data-num=1 data-exp_city = 'OTOPENI-IF' data-exp_distr = 'Ilfov' data_exp_city_val = 'OTOPENI-IF'>Some address in RO</option></select>
<input name="exp_city" type="text" id="exp_city" style="text-align:left;" value="OTOPENI-IF" size="30" readonly="readonly">
Если вы сравните значение и data-num att в теге option, вы увидите, что они отличаются на единицу, ПОЧЕМУ. Первое значение параметра выбирается при посадке на страницу, но при вводе города отображается следующее значение из запроса.
Как я могу обойти это?
Заранее спасибо, ребята.