我正在编写代码以用数据填充输入框。当用户单击该按钮时,代码必须填充并显示数据。但问题是它没有填充实物价值和在线价值。仅填充选定的键。
<div class="container p-5">
<h2><b>Utilization</b></h2>
<button class="btn btn-primary rounded-css mt-3" data-bs-toggle="modal" data-bs-target="#addUtilizationModal">Add New Data</button>
<div class="container mb-3">
<div class="mb-3 mt-2 col-md-3 text-center">
<div class="btn-group " role="group">
@foreach ($utilizationData as $utilization)
<button type="button" class="btn btn-secondary utilization-button"
onclick="populateUtilization('{{ $utilization->key }}', '{{ $utilization->physical_value }}', '{{ $utilization->online_value }}')">
{{ $utilization->key }}
</button>
@endforeach
</div>
</div>
<form action="/updateUtilYear" method="POST" enctype="multipart/form-data">
@csrf
<input id="selectedKey" name="selectedKey">
<div class="row mb-3">
<div class="col-md-6">
<div class="form-group">
<label for="physicalValue">Physical Value</label>
<input type="text" class="form-control" id="physicalValue" name="physicalValue" required>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="onlineValue">Online Value</label>
<input type="text" class="form-control" id="onlineValue" name="onlineValue" required>
</div>
</div>
</div>
<button type="submit" class="btn btn-primary">Update</button>
</form>
</div>
</div>
JS:
function populateUtilization(selectedKey, physicalValue, onlineValue) {
document.getElementById('selectedKey').value = selectedKey;
document.getElementById('physicalValue').value = physicalValue;
document.getElementById('onlineValue').value = onlineValue;
// Debug: Check the values after setting them in the input boxes
console.log('After setting values - Selected Key:', selectedKey);
console.log('After setting values - Physical Value:', physicalValue);
console.log('After setting values - Online Value:', onlineValue);
}
期待您的见解。
您确定对象利用率中的物理值和在线值不等于null?他们有价值观吗? 如果是这样,这两个值将作为 null 发送到 JavaScript 中的函数中,并且您的字段将设置为 null。