vendredi 18 décembre 2015

how to populate text field based on dropdown?

I have a dropdown which contains ID from database, so when I select one ID from the list based on the ID the text field must be populated.

<label class="col-md-2 control-label">Equipment ID:<span class="required">*</span></label>
                                <div class="col-md-9">
                                <select name="equipmentid" id="input18" class="select2-select-00 col-md-12  form-control input-width-xlarge form-control required"   multiple size="5">
                                <?php
                                $data = DB::table('tbl_addequipment')->where('last_month', '=', $data2)->get();

                                foreach ($data as $row2) {
                                                ?>
                                                <option  value="<?php echo "EQ".$row2->equipment_tag ?>"><?php echo "EQ".$row2->equipment_tag ?></option>

                                                <?php } ?>
                                                </select>
                                        </div>  

and my text field

<label class="col-md-2 control-label">Maintenance Type:<span class="required">*</span></label>
                                    <div class="col-md-10" >
                                        <input class="form-control input-width-xlarge form-control required" style="display: block; margin-top: 6px;" type="text" name="maintenancetype" id="maintenancetype" > 

                                    </div>

I have tried this code but doesn't work and I don't get error.

<?php


                                $data3 = $row2->equipment_tag ;
                                $data4 = DB::table('tbl_maintenancerecord')->where('equipment_tag', '=', $data3)->get(); 

                                ?>

<script type="text/javascript">
                                    $('select[name="equipmentid"]').change(function()
                                    {
                                         $('#maintenancetype').val($('select[name="equipmentid"] option:selected').data('mstatus'));
                                    }
                                    );
                                    </script>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire