如何在文本框中显示下拉列表选定值

When I choose from the dropdown list, I want to get the selected value of the dropdown list and show in the . But I try to do with above code, it didn't work ? whats wrong on that, plz suggest me. Thanks

$('.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>

You just need to pass value on change

    <script>

    function myFunction(value) {
        $('#idValue').text(value)
    }

        </script>
>>>>>>>>>> Drop Down List <<<<<<<<<<<<

And in your php code you need onchange="myFunction(this)" in select tag

<?
                        $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>

Hope this will help you

You use $('.assetgroupSelect') but you should use $('#assetgroupSelect') because it is (select id="assetgroupSelect"...) in HTML.

And also do not forget tu use semicolon here at the end of line: $('#idValue').text(value)

issue in .assetgroupSelectyou need us #assetgroupSelect' Because assetgroupSelect is ID not Class

try it

$('#assetgroupSelect').on('change', function () {
  var value = $('#assetgroupSelect').val();
  if (value != "") {            
    $('#idValue').text(value)
  }
}).trigger('change');

update Comment

$('#assetgroupSelect').on('change', function () {
  var value = $('#assetgroupSelect').val();
  if (value != "") {            
    $('#idValue').text(value)
  }
}).trigger('change');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<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>
     
      <option value="A"> A </option>
     <option value="B"> B </option>
     <option value="C"> C </option>
     <option value="G"> G </option>
     <option value="H"> H </option>
     <option value="I"> I </option>
     
    </select><br><br>
    <div class="placer"> 
      Current index is :
      <div id="idValue"></div>
    </div>
  </td>
</tr>

</div>