我在提交表单后尝试保留表单值。
20170512
它适用于日期选择器,但同样适用于选择选项。
HTML code:
document.getElementById('start_date').value = "<?php echo $_POST['start_date'];?>";
document.getElementById('end_date').value = "<?php echo $_POST['end_date'];?>";
用于动态填充选择下拉列表的JS代码:
<form id=Inputs action="" method="POST" onsubmit="return ray.ajax()">
<center><table>
<td align="left" width=200px> <b>Select The Product:</b>
<select name="product" id="product" onChange="changecat(this.value);changeenv(this.value);">
<option value="" disabled selected>Select</option>
<option value="MOBILE">MOBILE</option>
<option value="RAM">RAM</option>
<option value="CAT">CAT</option>
</select></td>
<td width=200px> <b>Select Data Center:</b>
<select name="dc" id="dc">
<option value="" disabled selected>Select</option>
</select></td>
<td width=200px> <b>Select Environment:</b>
<select name="env" id="env"><option value='NO' selected disabled>Select</option>
</select></td>
<td width=200px> <b>Select Start Date:</b>
<input type="date" name="start_date" id="start_date">
</td>
<td width=200px><b>Select End Date:</b>
<input type="date" name="end_date" id="end_date"></td></tr></table></center><br>
<div align="center"><input type="submit" class="button" value="Submit" name="submit" onclick="clearBox('tb')"> <input type="reset" class="button" value="Reset" name="reset" onclick="clearBox('tb')"></div>
<br>
</form>
答案 0 :(得分:0)
您的代码中有错误如下:
var environment = {
MOBILE: ["Select","Pr","Prv"],
RAM:["Select","Pr","Sl""], // Remove extra "
CAT:["Select","Pr","BS"],
}