[Solved] Populate a text box based on a dynamic drop down box in php


Add the rating to your HTML using a data attribute:

<select name="JournalID" id="JournalID">
<?php
    for($i = 0; $i < sizeof($journals); $i++) {
    print "<option value=\"" . $journals[$i][1] . "\" data-rating=\"" . $journals[$i][2] . "\">" . $journals[$i][0] . "</option>\r\n";
}
?>
</select>

Then you can access this using jQuery .data():

(function($) {
  $(function() {
    $("#JournalID").on('change', function() {
      $("#JournalRating").val($(this).find("option:selected").data('rating'));
    });
  });
})(jQuery);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="JournalID">
  <option>Select a journal</option>
  <option value="1" data-rating="3">Journal #1</option>
  <option value="2" data-rating="2">Journal #2</option>
  <option value="3" data-rating="5">Journal #3</option>
  </select>
<br>
Rating: <input id="JournalRating">

3

solved Populate a text box based on a dynamic drop down box in php