0
所以我有一個下拉每個表單更新值elemnt的Javascript的變化更新的輸入值中的foreach
這裏是我的組選擇框
echo $this->Form->input('groups', ['options' => $groups, 'id' => 'groups', 'class' => 'selectpicker', 'label' => false, "onchange"=>"updateGroupId(this.value)"]);
下面的代碼是代碼,我產生形成
<table class="table table-striped">
<tbody>
<?php foreach($allProducts as $product): ?>
<tr>
<td>
<form class="form-inline" name="uploadform-<?= $product->id ?>" id="uploadform-<?= $product->id ?>" onsubmit="return checkInput<?= $product->id ?>()" enctype="multipart/form-data" action="/upload/<?= $product->id ?>" method="post">
<span class="btn btn-primary btn-file">
<span><i class="zmdi zmdi-upload zmdi-hc-fw"></i><?= __('Upload CSV') ?></span>
<input id="browsefiles-<?= $product->id ?>" name="uploadcsv" type="file" required="required" />
<span id="errornotification-<?= $product->id ?>" class="hidden"><?= __('Select CSV File') ?></span>
</span>
<input type="text" name="group_id-<?= $product->id ?>" id="group_id-<?= $product->id ?>" value="<?= key($groups) ?>" />
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
這裏是我的javascript代碼
<?php
$i=0;
foreach ($allProducts as $product) {
?>
function updateGroupId(ish){
document.forms["uploadform-<?= $product->id ?>"]["group_id-<?= $product->id ?>"].value = ish;
} } ?>
使用此代碼,我可以僅更新上次輸入的更改值,但我需要所有輸入(groups_id)。