我在下面有一个脚本,用于从基于 INPUT TEXT 的选择标签中自动填充下拉菜单。我如何才能真正做到这一点,所以如果用户想要更改已自动填充的选项,他或她仍然可以更改什么已通过他或她选择的选项填充到下拉菜单中,同时仍保留自动填充功能,我希望它仍然自动填充,但如果用户不喜欢该选项,他仍然可以更改它.. 下面是自动填充下拉选择的工作脚本
<html>
<head> <title> validation </title >
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
<script type="text/javascript">
function checkValues()
{
jQuery("#ddl_StxName").val("stm3","stx2");
jQuery("#ddl_rtumodel").val("both");
ESNList = jQuery("#ESNList").val();
if((ESNList >= 986329) && (ESNList <= 999999))
{
jQuery("#ddl_StxName").val("stx2");
jQuery("#ddl_rtumodel").val("globalstar");
}
if ((ESNList >= 660000) && (ESNList <= 699999))
{
jQuery("#ddl_StxName").val("mmt");
jQuery("#ddl_rtumodel").val("globalstar");
}
if ((ESNList >= 200000) && (ESNList <= 299999))
{
jQuery("#ddl_StxName").val("stm3");
jQuery("#ddl_rtumodel").val("stmcomtech");
}
if ((ESNList >= 1202114) && (ESNList <= 1299999))
{
jQuery("#ddl_StxName").val("smartone");
jQuery("#ddl_rtumodel").val("globalstar");
}
// you should be able to follow the above and add your own conditions
}
function checkInput()
{
jQuery(":text").each(function (){
if (jQuery(this).val().length == 0)
{
jQuery(this).css("border", "2px solid red");
}
else
{
jQuery(this).css("border", "0");
}
});
}
setInterval(function () {checkInput();checkValues();}, 500);
</script>
<body>
<form id="provision">
ESNList: <input type="text" id="ESNList" name="ESNList" size="30" /> <br />
ESN Start:<input type="text" id="ESNStart" name="ESNStart" size="10" /> <br />
ESN End: <input type="text" id="ESNStart" name="ESNStart" size="10" /> <br />
UnitName:<input type="text" id="STxName" name="STxName" size="30" /> <br />
Unit Model: <select name="STxName" id="ddl_StxName">
<option value="stx2">STX2</option>
<option value="stm3" selected>STM3</option>
<option value="acutec">Acutec</option>
<option value="trackpack">Trackpack</option>
<option value="mmt">MMT</option>
<option value="smartone">Smartone</option>
<option value="smartoneb" >SmartOneB</option>
</select> <br />
RTU Model Type:
<select name="rtumodel" id ="ddl_rtumodel">
<option value="globalstar">GlobalStar</option>
<option value="both">Both</option>
<option value="comtech">Comtech</option>
<option value="stmcomtech">STMComtech</option>
</select> <br />
<input type="submit" value ="submit" />
</form>
</body>
</html>