[英]how I can get the ID of the selected option from a dynamically created dropdown using PHP, or Jquery?
[英]How can i get select option by id using php
我想使用php通過id訪問下拉列表選項,就像我在javascript中所做的一樣。我也想在php中進行此工作。有沒有辦法做到這一點。請指導。我的JS代碼是。
var opt = amove.options[amove.selectedIndex];
if(opt.id =="Exchange"){
document.getElementById('barcode2lb').style.display='block';
document.getElementById('barcode2txt').style.display='block';
}
else{
document.getElementById('barcode2lb').style.display='none';
document.getElementById('barcode2txt').style.display='none';
}
如果您使用原始PHP,則
<select name="">
<option value=""> select a option </option>
<?php
$sql = 'SELECT * FROM table ORDER BY id ASC';
$result_select = mysql_query($sql);
$rows = array();
while($row = mysql_fetch_array($result_select)){
if($row['which column you want to compare'] == value){
echo "<option value="".$row['value index']."">".$row['value index']." </option>"
}
}
?>
例如,
<select>
<?php foreach($yourArr as $row):
if(yourConidtion){
$selected='selected';
}else{
$selected='';
}?>
<option value="<?= $row->id?>" <?= $selected ?>><?= $row->name ?></option>
<?php endforeach;?>
</select>
我想這就是你要的
PHP
是一種服務器端語言,因此您將需要JS
來使用AJAX發布ID值。 通過JS
代碼進行AJAX調用,並處理PHP
代碼中的數據
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.