<div class = "container">
    <div class = "text-center">
        <h1>Gasóleo</h1>
    </div>
    <div class="container">
        <table>
            <thead>
                <tr>
                    <td style = "font-size:24px;"><b>ID</b></td>
                    <td style = "font-size:24px;"><b>Matricula</b></td>
                    <td style = "font-size:24px;"><b>Litros</b></td>
                    <td style = "font-size:24px;"><b>Kms</b></td>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <?= $this->Form->create($add, ['url' => array('action' => 'index'), 'role' => 'form', 'id' => 'form']) ?>
                    <?php echo $this->Form->hidden('user_id', ['value' => $_GET['user_id']]); ?>
                    <td><?php echo $this->Form->select('matricula_id', $matricula_id, ['id' => 'select1', 'empty' => true, 'class' => 'matricula_id', 'label' => false, 'required' => true, 'onchange' => 'myFunction1();']); ?></td>
                    <td><?php echo $this->Form->select('matricula_id', $matriculas, ['id' => 'select2', 'empty' => true, 'class' => 'matricula', 'label' => false, 'required' => true, 'onchange' => 'myFunction();']); ?></td>
                    <td style = "width:300px;"><?php echo $this->Form->input('litros', array('type' => 'number', 'placeholder' => 'Insira os litros gastos', 'required' => true)); ?></td>
                    <td style = "width:300px;"><?php echo $this->Form->input('kms', array('type' => 'number', 'placeholder' => 'Insira os quilometros percorridos', 'required' => true)); ?></td>
                    <td><?= $this->Form->button(('OK')); ?></td>
                    <?php echo $this->Form->end(); ?>
                </tr>
            </tbody>
        </table>
    </div>
</div>

<script type = "text/javascript">
    function myFunction() {
      document.getElementById("select1").value = document.getElementById("select2").value;
    }
    function myFunction1(){
        document.getElementById("select2").value = document.getElementById("select1").value;
    }
</script>