【发布时间】:2019-04-28 02:04:48
【问题描述】:
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Policy Creations</title>
<script type="text/javascript">
/* function autofillValues(country,state, city, pincode,branch,addrLine1,addrLine2){ */
function autofillValues(country){
console.log(country);
document.getElementById('country').value = country;
alert(document.getElementById('country').value);
/* document.getElementById('state').value = state;
document.getElementById('city').value = city;
document.getElementById('pincode').value = pincode;
document.getElementById('branch').value = branch;
document.getElementById('addrLine1').value = addrLine1;
document.getElementById('addrLine2').value = addrLine2; */
}
</script>
</head>
<body>
<h1># Policy Creation</h1>
<br>
<h2>Insurer Details</h2>
<form name="newPolicy" th:object="${insurerList}">
Insurer Name<sup>*</sup>
<!-- onchange = "autofillValues()" -->
<select onchange = "autofillValues('${insurerList')" >
<option value="">Select</option>
<option th:each = "insurer : ${insurerList}"
th:value = "${insurer.name}"
th:utext="${insurer.name}" />
</select>
Country<sup>*</sup> <input type="text" name="country" id="country"/>
State<sup>*</sup> <input type="text" name="state" id="state" value=""> <br><br>
City<sup>*</sup> <input type="text" name="city" id="city" value="">
Pincode<sup>*</sup> <input type="text" name="pincode" id="pincode" value="">
Branch<sup>*</sup> <input type="text" name="branch" id="branch" value="">
Address Line 1<sup>*</sup> <input type="text" name="addrLine1" id="addrLine1" value="">
Address Line 2 <sup>*</sup> <input type="text" name="addrLine2" id="addrLine2" value="">
</form>
</body>
</html>
我在项目中有一个要求,将下拉菜单显示给用户。下拉列表中显示的数据来自数据库并设置在一个对象中。然后迭代此对象以显示下拉列表.. 在我的情况下,该对象是一个数组列表(insurerList).. 在下拉列表中显示数据后,我想自动填充其值存在于 insurancelist 对象中的其他文本框...
谁能告诉我如何在 html 中实现这个功能?
iam 使用 spring mvc....insurerList 的值在 spring mvc 的模型属性中设置... 也欢迎任何其他解决此问题的方法...
【问题讨论】:
标签: javascript html spring-mvc thymeleaf