Jump to content

simrantechy

New Members
  • Posts

    2
  • Joined

  • Last visited

Posts posted by simrantechy

  1. On 6/28/2022 at 6:08 AM, Barand said:

    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"/>

    image.png.0c0d734b2784de4cef9b755de16d091f.png

    Not working for me, Was reading this post but fixing this but not able to do that.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.