'My modal can not receive data from jquery script in Laravel

So I have modal script like this:

<div class="modal" id="assignstore" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
.....some of code.....
        <div class="row mb-3">
           <label for="name" class="col-md-4 col-form-label  text-md-end">
              {{ __("Subject") }}
            </label>
                 <div class="col-md-6">
                     <input id="title-as">
                 </div>
         </div>
    </div>
</div>

And I have data from here:

<a href="#" 
    data-target="#assignstore" 
    data-toggle="modal" 
    data-titleas="{{ $subject->title }}"
    data-idas="{{ $subject->id }}" 
    class="a btn btn-warning"
>
    Assignment 
</a>

This is my Jquery Script:

<script>
    $('#assignstore').on('show', function(e) {
        var link = e.relatedTarget(),
            modal = $(this),
            id = link.data("idas"),
            title = link.data("titleas");

        modal.find("#title-as").val(title);
        modal.find("#id-as").val(id);
    });
</script>

Could you help me to find out what's wrong with my script?



Solution 1:[1]

it depends what error you receive. btw here is some solutions (maybe it works for you) :

  1. replace your script (make sure jquery runs before ur script)
  2. change the way ur script fires
  3. what is $subject on ur code? if it is an item of an array we should know what is this item (make sure u r calling items well)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ali Safaei