input hidden cant achieve in modal javascript

Posted 1 month ago by FareedR

i put input hidden for id at below foreach . when i call modal to popup . it cant define where the id is . view

@foreach($clubs as $club)
                <input type="hidden" id="club_id" value="{{ $club->id }}">
                    <tr>
                        <td class="text-center">{{ $i++ }}</td>
                        <td class="font-w600">
                            <a href="" class="btn btn-primary">{{ $club->name }}</a>
                        </td>
                        <td class="text-center">
                            <span class="badge badge-primary">{{ $club->adviser_id }}</span>
                        </td>
                        <td class="text-center">
                            <span class="badge badge-warning">{{ $club->president_id }}</span>
                        </td>
                        <td class="text-center">
                            <span class="badge badge-info">{{ $club->secretary_id }}</span>
                        </td>
                        <td class="text-center">
                            @if($club->status == 1)
                                <span class="badge badge-primary">Active</span>
                            @else
                                <span class="badge badge-danger">Inactive</span>
                            @endif
                        </td>
                        <td class="text-center">
                            @if(empty($club->adviser_id))
                                <button type="button" class="btn btn-sm btn-rounded btn-warning" data-toggle="modal" data-target="#modal-fadein" title="Assign Adviser">
                                    Assign Adviser
                                </button>
                            @endif
                            <button type="button" class="btn btn-sm btn-rounded btn-info" data-toggle="tooltip" title="Review Club Profile">Review Club
                            </button>
                            <a href ="{{ route('view-edit-club-university',$club->id ) }}"class="btn btn-sm btn-rounded btn-primary" data-toggle="tooltip" title="Edit Club Profile">
                                Edit Club
                            </a>
                        </td>
                    </tr>
                @endforeach

modal

<div class="block block-themed block-transparent mb-0">
                    <div class="block-header bg-primary-dark">
                        <h3 class="block-title">Available Adviser</h3>
                        <div class="block-options">
                            <button type="button" class="btn-block-option" data-dismiss="modal" aria-label="Close">
                                <i class="si si-close"></i>
                            </button>
                        </div>
                    </div>
                    <div class="block-content">
                        <label>Adviser Name</label>
                        <select name="id" id="adviser_id" class="form-control">
                            <option value="0">--Choose Adviser--</option>
                        @foreach($advisers as $adviser)
                            <option value="{{ $adviser->id }}">{{ $adviser->name }}</option>
                        @endforeach
                        </select>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-alt-secondary" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-alt-success" onclick="assignAdviser()">
                        <i class="fa fa-check"></i> Assign
                    </button>
                </div>

javascript

function assignAdviser(){
       var club_id = $('#club_id').val();
       var adviser_id = $('#adviser_id').val();
       console.log(club_id);
       swal({
           title: "Are you sure to assign this adviser?",
           icon: "warning",
           buttons: true,
           dangerMode: true,
       })
       .then((willAssign) => {
           if (willAssign) {
                $.ajax({
                   url : "{{ url('/assign-adviser-club') }}" + '/club/' + club_id + '/adviser/' + adviser_id,
                   type : "POST",
                   success: function(){
                       swal({
                           title: "Success",
                           text: "Adviser has been assigned! \n Click OK to refresh the page",
                           icon: "success",
                        }).then(function(){
                           location.reload();
                        });
                   },
                   error : function(){
                       swal({
                           title: "Opps...",
                           text : "Something wrong occured",
                           icon: "error",
                           timer: 1500
                       })
                    }
               })
           }else{
               swal("Nothing happen here");
           }
       });
    }

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.