我现在有一个脚本,可以防止用户在我的表单的状态字段中输入除状态缩写之外的任何内容。感谢吉迪恩
我稍微修改了脚本,以便在输入无效状态时包含一条警报消息。但我真的不喜欢它。我想要一个在页面顶部或字段正下方闪烁的警报栏。当输入不正确的缩写时自动出现的东西并闪烁以吸引用户的注意力并在几秒钟后消失。欢迎任何想法或想法!我非常愿意接受建议!再次感谢!
我开始认为你们不理解我。这是我的代码:
<script>
function validateState(el) {
//put all states in this array.
var states = ["AK","AL","AR","AS","AZ","CA","CO","CT","DC","DE",
"FL","GA","GU","HI","IA",
"ID","IL","IN","KS","KY","LA","MA","MD","ME","MH","MI","MN","MO","MS","MT",
"NC","ND","NE","NH","NJ","NM","NV","NY","OH","OK","OR","PA","PR","PW","RI",
"SC","SD","TN","TX","UT","VA","VI","VT","WA","WI","WV","WY"];
for(var i=0;i< states.length;i++) {
if(el.value.toUpperCase() == states[i]) {
return true;
}
}
//clear element if it doesn't match a state
el.value = ""; //you could maybe do something else here.
alert('Invalid State Abbreviation, You must fix this before continuing')
document.getElementById("state").focus();
return false;
}
</script>
如果语句返回 false,我希望在屏幕上运行一个条形图。