我正在使用Java对象转换为表单,并且不同字段的值基于该对象内不同字段的初始值。我有一个Select Option下拉值来自该对象内的ArrayList。我想根据所选选项更新其他字段。如何使用JavaScript执行此操作。代码段如下: 我计划使用带有process()函数的外部Javascript文件,可以将“ perTestBuildConfig”对象和选择选项传递给该Javascript文件,以便我可以基于选择选项更新其他字段。
<form action="#" th:action="@{/save(env=${env})}" th:object="${perTestBuildConfig}" method="post">
<div>
<div class="form-group row">
<div class="col-xs-2">
<label>Select Test To run</label>
<select class="form-control" id="inputService" th:field="*{testType}" th:onchange="process()">
<option th:each="i : ${perTestBuildConfig.testTypeList}" th:text="${i}" th:value="${i}">>
</option>
</select>
</div>
<div class="col-xs-2">
<label>Service to test</label>
<input class="form-control" type="text" th:field="*{serviceToTest}" id="serviceToTest"
placeholder="Test to run">
</div>
</div>
<div class="form-group row">
<div class="col-xs-2">
<label>Service1</label>
<input class="form-control" type="text" th:field="*{throughputService1}" placeholder="Throughput Service1">
</div>
<div class="col-xs-2">
<label>Service2</label>
<input class="form-control" type="text" th:field="*{throughputService2}" placeholder="Throughput Service2">
</div>
</div>
</form>