Use data attributes for the options
<?php
$data = [
[ 'id' => 1, 'rifleName' => '.308 Bolt action', 'em' => '225', 'gm' => '1350' ],
[ 'id' => 2, 'rifleName' => '7mm magnum', 'em' => '300', 'gm' => '1575' ],
[ 'id' => 3, 'rifleName' => '.243 LeverAction', 'em' => '215', 'gm' => '8725' ]
];
?>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script type='text/javascript'>
$().ready(function() {
$("#menu").change( function() {
let em = $(this).find("option:selected").data("em")
let gm = $(this).find("option:selected").data("gm")
$("#em").val(em)
$("#gm").val(gm)
})
})
</script>
<select class='nameItems' id="menu" name="selection">
<option value="">Choose a Rifle</option>
<?php
foreach ($data as $row) {
echo "<option value={$row['id']} data-em='{$row['em']}' data-gm='{$row['gm']}'>" . htmlspecialchars( $row["rifleName"] ) . "</option>";
}
?>
</select>
em:<input type="text" class="charge-type" name="em" id="em" value="0" disabled size="5"/>
gm: <input class="charge-type" name="gm" id="gm" value="0" disabled size="5"/>