我有一个文本框,用于输入汽车注册号码。注册基于年份,格式为GT 74454 12
,最后一位数12
代表年份2012
这意味着这辆车在2012
注册。我想要一个将自动检测最后两位数字并影响下拉列表值的脚本。基于文本域中最后2个变量的下拉列表更改值
例如,如果年份范围从09 - 12
下拉的值应该是红色。如果范围从13 - 16
,则下拉列表的值应变为蓝色。
HTML
<form id="form1" name="form1" method="post" action="">
<label for="car_no"></label>
<input type="text" name="car_no" id="car_no" />
<label for="select"></label>
<select name="select" id="select">
<option>Color Code</option>
<option>Red</option>
<option>Blue</option>
<option>White</option>
</select>
</form>
EDIT
there are some registrations that comes in a different format too which goes like this "GT 74454 X". How do i make the script autodect if the last digit is an alphabet the value shoud change to white
你可以请张贴迄今为止已经尝试过的js吗? – Rhono
2009年之前注册的汽车应该发生什么和/或不适合这种格式? –
@DavidThomas,这是一个伟大的建议,我修改了帖子 –