的Javascript的变化更新的输入值中的foreach

所以我有一个下拉每个表单更新值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)。

回答:

我已经想出了一个答案,所以如果有人需要解决这里它是!

所以,这是如何使用选择框(on.change功能)

选择框 选择输入需要相同名改变所有的输入值 - >

"onchange"=>"updateGroupId(this.value)" 

输入变化

<input type="hidden" name="group_id" value="<?= key($groups) ?>" /> 

和JS代码

function updateGroupId(ish){ 

var group_ids = document.getElementsByName('group_id');

for (var i=0;i<group_ids.length;i++) {

group_ids[i].value = ish;

}

}

以上是 的Javascript的变化更新的输入值中的foreach 的全部内容, 来源链接: utcz.com/qa/265244.html

回到顶部