[英]How can i get select option by id using php
I want to access option of dropdowns by id using php like i have done in javascript .I want to do this work in php also.Is there any way to do this.Please guide.My JS code is. 我想使用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';
}
if you using raw php then 如果您使用原始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>"
}
}
?>
For example, 例如,
<select>
<?php foreach($yourArr as $row):
if(yourConidtion){
$selected='selected';
}else{
$selected='';
}?>
<option value="<?= $row->id?>" <?= $selected ?>><?= $row->name ?></option>
<?php endforeach;?>
</select>
I think this is what you asked for 我想这就是你要的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.