简体   繁体   English

如何从模态中的选定行中获取价值?

[英]How to get value from selected row in a modal?

When i select a row from a table, then open a modal with input fields which I can edit, but I am sending to query only first row data. 当我从表中选择一行时,然后使用可以编辑的输入字段打开模式,但我仅发送查询第一行数据。

How I can get value from selected row? 我如何从选定的行中获取价值? In modal inputs I get correct rows data. 在模式输入中,我得到正确的行数据。

$('.targetClass').submit(function(event) {
    event.preventDefault();
    $.ajax({
        type: 'POST',
        url: '/binitex_task/index/edit',
        data: {
            name: $('#name_id').val(),
            surname: $('#surname_id').val(),
            year_of_birth: $('#year_of_birth_id').val(),
            city_of_birth: $('#city_of_birth_id').val(),
            university: $('#university_id').val(),
            insurance_number: $('#insurance_number_id').val(),
            id: $('img').attr('id')
        },
        success: function() {}
    });
});

Modal with form where the input fields are, where is the value which I need to send to query to update a database table. 输入字段的形式为模态,哪里是我需要发送以查询更新数据库表的值。

<div class="modal-body">
    <form method="POST" class="targetClass" id='target'>
        <input id='name_id' type="text" name="name" value="<?php echo $student['name']; ?>">
        <input id='surname_id' type="text" name="surname" value="<?php echo $student['surname']; ?>">
        <input id='year_of_birth_id' type="text" name="year_of_birth" value="<?php echo $student['year_of_birth']; ?>">
        <input id='city_of_birth_id' type="text" name="city_of_birth" value="<?php echo $student['city_of_birth']; ?>">
        <input id='university_id' type="text" name="university" value="<?php echo $student['university']; ?>">
        <input id='insurance_number_id' type="text" name="insurance_number" value="<?php echo $student['insurance_number']; ?>">
        <input id="saveBtn" name='save' type="submit">
    </form>
</div>

Do u mean that u have many rows of "name_id, surname_id, year_of_birth_id, etc..."??? 你的意思是你有很多行是“ name_id,surname_id,year_of_birth_id等”吗???? (and u want to edit a specific row of the record) (并且您想编辑记录的特定行)

That being the case, then the $('img').attr('id') should be the problem. 既然如此,那么$('img')。attr('id')应该是问题所在。 If u call $('img'), u would be calling the first row that containing the "img". 如果您调用$('img'),则您将调用包含“ img”的第一行。 Also, u cant use "id=xxxx" if u have many rows of data. 另外,如果您有许多数据行,则不能使用“ id = xxxx”。 (reason is same as the $('img') problem) (原因与$('img')问题相同)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM