Select a selected: true from another Select


For some reason you do not select me on the second Select. I have not asked the question without checking before, but it does not work for me. I have a Select that depending on what I choose, I will select by default any of the options that I already have loaded in the other one. This is my php:

<div class="row">
  <div class="col-sm-7">
    <div class="form-group">
      <label class="control-label">Seleccione el Movimiento a realizar</label>
      <select class="form-control selectpicker operation_id" id="operation_id" name="operation_id">
        <option style="display:none" selected="selected" value="">Choose here </option>
        <?php foreach ($operations as $mprod): ?>
        <option value=<?=$mprod->operation_id?> >
          <?=$mprod->operation_code?> -
        <?php  endforeach;?>
  <div class="col-sm-5">
    <div class="form-group">
      <label class="control-label">Almacen</label>
      <select class="form-control selectpicker store_eid" id="store_eid" name="store_eid">
        <?php foreach ($stores as $store): ?>
        <option value=<?=$store->store_id?> >
          <?=$store->store_code?> -
        <?php  endforeach;?>

and this is my javascript

<script type="text/javascript">

$(".operation_id").change((e) => {


If you realize, I'm passing a default value to see if it works and nothing. Thanks in advance.

asked by Delvis Díaz 27.12.2018 в 19:56

1 answer


Excuse me, I kept trying and I found it:

let index = 2;

You should only reload the Select after assigning the value.

answered by 27.12.2018 в 20:07