简体   繁体   中英

How modal box show by mouse click in select box at the Laravel?

I wish to show modal box when mouse clicked to "Andre..." at the list select box in the Laravel code as below. but this is not working. Could you tell me where is incorrect to work?

Select Box

在此处输入图片说明

Variable define in Controller

$job_types = DB::table('jobs')->pluck('job_type')
                    ->unique(function ($item){
                        return $item;
                      });;

HTML(Laravel Blade)

Job Type Field
<div class="form-group col-sm-4" id="job_type">
    {!! Form::label('job_type', 'Type:') !!}

    {!! Form::select('job_type', $job_types, null, ['class' => 'form-control', 'id' => 'job_type']) !!}
</div>

Modal view

<div class="modal fade" id="jobListModal">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span>
          </button>
          <h4 class="modal-title">Set in new job type.</h4>
        </div>
        <div class="modal-body">
          <p>New Job type:</p>
          <input type="text" id="textInput">
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
          <button type="button" id="btnSave" class="btn btn-primary">Edit</button>
        </div>
      </div>
      <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
  </div>
  <!-- /.modal -->

Jquery

$('#job_type').on('change', function (e) {
    if ('Another' == this.value) {
        $("#jobListModal").modal("show");
    }
});
$('#btnSave').click(function () {
    var newType = $('input#textInput').val();
    $('select#job_type option:last')
        .after('<option value="' + newType + '" selected="selected" >' + newType + '</option>');
    $('#jobListModal').modal('hide');
});

Inspection

在此处输入图片说明

Try This : if you want to match by dropdown text

$('#job_type').on('change', function (e) {
    if ('Another' == $('#job_type option:selected').text() {
        $("#jobListModal").modal("show");
    }
});

Try changing this code part to:

$('#job_type').on('change', function (e) {
    if ('59' == $(this).val()) {
        $("#jobListModal").modal("show");
    }
});

Have u tried This

$('#job_type').on('change', function (e) {
    if (59 == $(this).val()) {
        $("#jobListModal").modal("show");
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM