当我从下拉列表中选择时,我想获取下拉列表的选定值并显示在。但我试着用上面的代码做,它没有用?什么是错的,plz建议我。感谢
$('.assetgroupSelect').on('change', function () {
var value = $('.assetgroupSelect').val();
if (value != "") {
$('#idValue').text(value)
}
}).trigger('change');
<?
$select_query = "Select Group_ID, Group_Name from Asset_Group";
global $DB;
$arrResult = array();
$err_mess = 'Test';
$result = $DB->Query($select_query, false, $err_mess.__LINE__);
?>
<tr height="50">
<td style="width: 220px">
<label for="assetGroup">
<span style="color:red">*</span>Asset Group:
</label>
</td>
<td>
<select id="assetgroupSelect" name ='assetgroupSelect'>
<option value="">(choose asset group)</option>
<? while ($arrResult = $result->Fetch()) { ?>
<option value="<? echo $arrResult['Group_ID'] ?>"> <? echo $arrResult['Group_Name'] ?> </option>
<? } ?>
</select><br><br>
<div class="placer">
Current index is :
<div id="idValue"></div>
</div>
</td>
</tr>
答案 0 :(得分:0)
您使用$('。assetgroupSelect'),但您应该使用$('#assetgroupSelect'),因为它是(选择id =“assetgroupSelect”...)HTML。
并且不要忘记在行尾使用分号: $( '#idValue')。文本(值)
答案 1 :(得分:0)
您只需要在变更时传递价值
<script>
function myFunction(value) {
$('#idValue').text(value)
}
</script>
>>>>>>>>>> Drop Down List <<<<<<<<<<<<
在您的PHP代码中,您需要onchange =&#34; myFunction(this)&#34;在选择标记
<?
$select_query = "Select Group_ID, Group_Name from Asset_Group";
global $DB;
$arrResult = array();
$err_mess = 'Test';
$result = $DB->Query($select_query, false, $err_mess.__LINE__);
?>
<tr height="50">
<td style="width:220px"><label for="assetGroup"><span style="color:red">*</span>Asset Group:</label></td>
<td>
<select id="assetgroupSelect" name ='assetgroupSelect' onchange="myFunction(this)">
<option value="">(choose asset group)</option>
<?while ($arrResult = $result->Fetch()){?>
<option value = "<? echo $arrResult['Group_ID'] ?>"> <? echo $arrResult['Group_Name'] ?> </option>
<?}?>
</select><br><br>
<div class="placer"> Current index is :
<div id="idValue"></div>
</div>
</td>
</tr>
希望这会对你有所帮助
答案 2 :(得分:0)
问题您需要我们.assetgroupSelect
因为assetgroupSelect是ID而不是Class
试一试
#assetgroupSelect'
更新评论
$('#assetgroupSelect').on('change', function () {
var value = $('#assetgroupSelect').val();
if (value != "") {
$('#idValue').text(value)
}
}).trigger('change');
$('#assetgroupSelect').on('change', function () {
var value = $('#assetgroupSelect').val();
if (value != "") {
$('#idValue').text(value)
}
}).trigger('change');