Как передать данные в модальную форму с помощью jQuery в Laravel

#jquery #laravel

#jquery #laravel

Вопрос:

У меня есть этот код в Laravel-5.8:

 <button type="button" class="btn btn-xs btn-warning" data-toggle="modal" data-target="#comment_emp{{ $goal->id }}" data-original-title="Comment"> 
         <i class="fas text-white">Add Comment</i>
</button>
  

Кнопка выше генерирует модальную форму, как показано ниже:

 <div class="modal fade" id="comment_emp{{ $goal->id }}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <form action="{{route('appraisal.appraisal_year_end_setups.employee_year_end_comment',['id'=>$goal->id])}}" method="post" enctype="multipart/form-data" id="review_comment-form">
        {{ csrf_field() }}
        <div class="modal-header">
          Self-Review Comment
        </div>
        <div class="col-md-12">
          <div class="form-group">
            <label class="control-label"> Rating:<span style="color:red;">*</span></label>
            <input type="hidden" id="myRatingLimit" value="{{ $goal->goaltype->ratingLimit ? $goal->goaltype->ratingLimit->max_rating : '' }}">
            <input type="hidden" id="myWeightedScore" value="{{$goal->weighted_score ?? '' }}">
            <input type="text" id="myRating" name="employee_year_end_weighted_score" class="form-control myRating" onkeyup="checkScore(this.value)" required>
          </div>
        </div>
        <div class="modal-footer">
          <button type="submit" class="btn btn-success btn-ok">Save</button>
        </div>
      </form>
    </div>
  </div>
</div>  

Как мне передать эти данные (myRatingLimit и myWeightedScore):

 <input type="hidden" id="myRatingLimit" value="{{ $goal->goaltype->ratingLimit ? $goal->goaltype->ratingLimit->max_rating : '' }}">
<input type="hidden" id="myWeightedScore" value="{{$goal->weighted_score ?? '' }}">
  

в:

 < script type = "text/javascript" >
  $(document).ready(function() {

    $('#comment_emp{{ $goal->id }}').on('show.bs.modal', function(event) {

    });

  }); <
/script>  

Ответ №1:

Не работает это?

     $('#MODAL_id or .ModalClass').on('show.bs.modal', function(event) {
     $("#myRatingLimit").val();
     $("#myWeightedScore").val();
    });