javascript - PHP : Get values outside of foreach -


i have nested foreach loops in html table :

@foreach ($getusers $key => $commits)     @foreach ($commits->getlinks $key1 => $links)         <tr>             <td>                 <input type="hidden" name="" id="applicant_id" value="{{$commits->id}}">             <td>         <tr>     @endforeach @endforeach 

next have form need id of row defined in hidden field in foreach loop above.

below in form have have hidden input field pushing foreach hidden filed value form hidden field value but gives 1 id (same id every table row).

jquery getting id foreach hidden input to form hidden input :

    $(document).ready(function(){         var applicant_id = $('#applicant_id').val();         $("#applicant").val(applicant_id);     }) 

form

<form class="form-horizontal" method="post" action="{{route('upload-agreement')}}" enctype="multipart/form-data">     {{csrf_field()}}     <input type="hidden" name="applicant" id="applicant" >     <input type="file" name="file" class="form-control" required="">     <button type="submit" class="btn btn-primary">save changes</button> </form> 

issue : above method gives me same id.

based on comment, , fact have 1 form. need dynamically load correct id providing button or user click on.

@foreach ($getusers $key => $commits)   @foreach ($commits->getlinks $key1 => $links)     <tr>         <td>             <button class="edit" data-id="{{$commits->id}}" >edit</button>         <td>     <tr>   @endforeach @endforeach   $(document).ready(function(){     $('.edit').click(function(){         $("#applicant").val($(this).data('id'));     }); }); 

i put form in modal window of sorts...so can have pop when click, provides interactive easy follow user experience.

i've provided example. (requires bootstrap framework)

js

$(document).ready(function(){     $('.edit').click(function(){         $('#mymodal').modal({backdrop:'static'});         $("#applicant").val($(this).data('id'));     }); }); 

html

<div id="mymodal" class="modal fade" role="dialog">   <div class="modal-dialog">    <div class="modal-content">     <div class="modal-header">       <button type="button" class="close" data-dismiss="modal">&times;</button>     <h4 class="modal-title">upload file</h4>   </div>   <div class="modal-body">     <form class="form-horizontal" method="post" action="{{route('upload-agreement')}}" enctype="multipart/form-data">        {{csrf_field()}}        <input type="hidden" name="applicant" id="applicant" >        <input type="file" name="file" class="form-control" required="">       <button type="submit" class="btn btn-primary">save changes</button>     </form>   </div>   <div class="modal-footer">     <button type="button" class="btn btn-default" data-dismiss="modal">close</button>   </div> </div> 


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -