get params dal bootstrap modale al field di input

Ho qualche errore con il mio codice, uso bootstrap v3.3 con jquery predefinito da bootstrap, angolo v1.4 e dirPagination diretto per la tabella di tabella. Sto usando bootstrap modale per passare un valore dal field di input sul field modale da immettere nella pagina padre. Questo è il mio codice:

.js

$(function() { $('#listUser').on('click', '.pilih', function(e) { var samaccountname = $('#samaccountname_modal').val(); //pass from here //var question = $('#question_modal').val(); //pass from here $('#samaccountname_input').val(samaccountname); //to here //$('#question_input').val(question); //to here $('#listUser').modal('hide'); //close modal //console.log(samaccountname); //console.log(question); }); }); 

il mio field di input html

 <div class="input-group col-md-11"> <span class="input-group-addon"> <button type="button" class="btn btn-info btn-sm pull-right" data-target="#listUser" data-toggle="modal"><i class="material-icons">face</i></button> </span> <div class="form-group is-empty"><!-- id=samaccountname get value from modal --> <input type="text" name="samaccountname" id="samaccountname_input" class="form-control" placeholder="click blue button for search.." readonly required /> <span class="material-input"></span> <span id="result" /> </div> 

poi il mio modale

 <!-- Modal Add --><div class="modal fade" id="listUser" role="dialog"> <div class="modal-dialog"> <!-- Modal content--> <div class="modal-content"> <div class="modal-header"> </div> <div class="modal-body" ng-controller="ctrlList"> <form class="form"> <div class="col-md-12"> <div class="input-group"> <span class="input-group-addon"> <i class="material-icons">search</i> </span> <div class="form-group is-empty"> <input autofocus type="text" class="form-control" ng-model="search" placeholder="Type text here.." /> <span class="material-input"></span> </div> </div> </div> </form> <table class="table table-bordered table-hover table-striped"> <thead> <tr style="font-size:12px;"> <th style="text-align: center;">No</th> <th style="text-align: center;" ng-click="sort('nik')">NIK <span class="glyphicon sort-icon" ng-show="sortKey=='nik'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span> </th> <th style="text-align: center;" ng-click="sort('nama_karyawan')">Nama Karyawan <span class="glyphicon sort-icon" ng-show="sortKey=='nama_karyawan'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span> </th> <th style="text-align: center;" ng-click="sort('jabatan')">Jabatan <span class="glyphicon sort-icon" ng-show="sortKey=='jabatan'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span> </th> <th style="text-align: center;" ng-click="sort('department')">Department <span class="glyphicon sort-icon" ng-show="sortKey=='department'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span> </th> <th>Pilih</th> </tr> </thead> <tbody> <tr dir-paginate="adb in dataTable | orderBy:sortKey:reverse | filter:search | itemsPerPage: pageSize" pagination-id="listuserldap" style="font-size: 11px;"> <td>{{ $index+1 }}</td> <td>{{ adb.nik }}</td> <td>{{ adb.nama_karyawan }}</td> <td>{{ adb.jabatan }}</td> <td>{{ adb.department }}</td> <td><!-- here my button pass to input value --> <input class="btn btn-xs pilih" type="button" value="{{ adb.nik }} , {{ adb.nama_karyawan }}" id="samaccountname_modal" /> </td> </tr> </tbody> </table> </div> <div class="modal-footer"> <div ng-controller="ctrlPagination"> <div class="text-center"> <dir-pagination-controls pagination-id="listuserldap" boundary-links="true" on-page-change="pageChangeHandler(newPageNumber)" template-url="<?php echo Config::get('URL'); ?>pagination"></dir-pagination-controls> </div> </div> </div> </div> </div> 

e risultato mymodal

e il mio problema se io scatto altro che no 1 sul tabella modale, il field di input valore sul menu padre sempre passare da non 1. ti prego di darmi una sola soluzione, per favore grazie

ikwijaya

è necessario get il valore del button attualmente cliccato in modo da utilizzare solo $(this).val();

modificare :

  var samaccountname = $('#samaccountname_modal').val(); 

A :

 var samaccountname = $(this).val(); 

NOTA :

l'attributo id non dovrebbe ripetere l'attributo .id deve essere univoco