如何使用php和jquery获取特定的行文本字段值?

时间:2022-11-27 11:29:35

Hi i want to do the update function where each staff balance is listed in a row of the table. When the form is submit, it will only submit the specific row. Something like this.

嗨我想做更新功能,其中每个员工余额列在表格的一行中。提交表单时,它只会提交特定的行。像这样的东西。

Preview

预习

I am newbie to jquery, can someone give me a direction?

我是jquery的新手,有人能指点我吗?

<table id="rounded-corner">
        <thead>         
            <tr>
                <th scope="col" class="rounded-company">Name</th>
                <th scope="col" class="rounded">Position</th>
                <th scope="col" class="rounded">Annual Leave Balance</th>
                <th scope="col" class="rounded">Sick Leave Balance</th>
                <th scope="col" class="rounded">Action</th>
            </tr>
        </thead>        
<tbody>
<?php foreach($list as $value) {?>
    <tr id='<?php echo $value['IDSTAFFTABLE']; ?>'>
        <td><?php echo $value['FIRSTNAME']; ?> <?php echo $value['LASTNAME']; ?></td>
        <td><?php echo $value['POSITIONNAME']; ?></td>
        <td><input type="text" name="annualleave" class="annualleave" value="<?php echo $value['ANNUALLEAVE']; ?>"/></td>
        <td><input type="text" name="sickleave" class="sickleave" value="<?php echo $value['SICKLEAVE']; ?>"/></td>
        <td><input type="submit" name="submit" class="submit" value="Submit" /></td>            
    </tr>
    <?php } ?>
    </tbody>

1 个解决方案

#1


0  

First of all add a form to your html code inside the php foreach loop like this...

首先在php foreach循环中为你的html代码添加一个表单,如下所示...

<!-- Making use of foreach...endforeach is much better -->
<!-- when using annotated php code in html -->

<?php foreach($list as $value): ?>
  <form action="something" method="post">
  <!-- Rest of the code remains same -->
  </form>
<?php endforeach; ?>

Then use this jquery to submit the specific form...

然后使用此jquery提交特定表单...

$('input.submit').click( function() {
    $(this).parent("form").submit();
});

This code will fire a click event whenever an input with class "submit" is pressed, and it will submit its parent form.

只要按下“submit”类的输入,此代码就会触发click事件,并且它将提交其父表单。

#1


0  

First of all add a form to your html code inside the php foreach loop like this...

首先在php foreach循环中为你的html代码添加一个表单,如下所示...

<!-- Making use of foreach...endforeach is much better -->
<!-- when using annotated php code in html -->

<?php foreach($list as $value): ?>
  <form action="something" method="post">
  <!-- Rest of the code remains same -->
  </form>
<?php endforeach; ?>

Then use this jquery to submit the specific form...

然后使用此jquery提交特定表单...

$('input.submit').click( function() {
    $(this).parent("form").submit();
});

This code will fire a click event whenever an input with class "submit" is pressed, and it will submit its parent form.

只要按下“submit”类的输入,此代码就会触发click事件,并且它将提交其父表单。