2010-08-17 44 views
0

嗨,我想要做的更新功能,其中每個員工的平衡列在表中的一行。表單提交時,它只會提交特定的行。像這樣的東西。如何使用php和jquery獲取特定的行文本字段值?

Preview

我是新手到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> 

回答

0

首先的形式添加到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; ?> 

然後使用這個jQuery提交的具體形式...

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

此代碼每次按下帶班「提交」的輸入會觸發一個click事件, 並且會提交它的父表單。

相關問題