There is a page where a list of all users is displayed. You can also edit information about the user. It is necessary to do so that when you click on the Редактировать пользователя button Редактировать пользователя a modal window opens and information about the user (first name, last name, etc.) is passed to the input window of this window.
Code:
<!-- В цикле перебираем всех пользователей--> ... { <td><?= $ps['name'];?></td> <td><?= $ps['firstName'];?></td> <button class="editUser<?=$ps['id']?>" id="<?=$ps['id'] ?>" value="..."> Редактировать пользователя </button> } <!-- Модальное окно куда все нужно передать--> <div id="myModal" class="modal fade"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-body"> <input type="hidden" class="userId" id=""> <input type="text" class="userName" name="userName" value=""> ... </div> <div class="modal-footer"> <button type="button" class="btn btn-default"data-dismiss="modal">Закрыть</button> <button type="button" class="btn btn-primary" id="">Сохранить изменения</button> </div> </div> </div> <!-- Скрипт который должен передавать значение в модальное окно!--> <script> $(document).ready(function(){ $(".btn").click(function() { var id = this.id; var userName = $('.editUser' + id).val(); $('#myModal .userId').data('id', id); $('#myModal .userName').data('userName', value); $("#myModal").modal('show'); }); }); </script> For some reason, the data does not come. And everywhere is empty. What am I doing wrong? How can I transfer variable values to a modal window?
data-attribute, not the field value. Moreover, you retrieve the data inusernameand you record somevalue. But in general, a strange approach, it is not clear why everything should be written down / duplicated in the button if it is recorded in the table cells - teran Septembervalue- r.mcreal.data('id', id)but.val(id)- teranvalue. Now you need to send the modifiedvaluefrom the modal window. If I change it just in the input, then nothing happens, as it has come, it remains so, nothing changes - r.mcreal