我正在使用一个使用javascript-coder的gen_validatorv4脚本的表单。 (过去曾使用它取得巨大成功)。这个表格是这样的,我工作的银行的计票员可以将信息放入无效的支票,发送回我们的会计部门,并作为Foxtrot的csv被踢出。
我已经在Firefox和Chrome中测试了该脚本,没有任何问题。但是,在IE 8和9中,我收到消息“第1行:你的帐号必须是一个数字!”,这是一个验证错误,因为没有在该行中放一个数字,而且据我所知,它是因为我正在使用数组。当尝试在maxlen下执行此操作时,它将再次重复出错。我正在使用数组(由前一个表单创建),因为可以在任何给定时间提交一组可变数量的变量。
任何人都有任何想法如何使其在Internet Explorer中正常运行?
更新:http://jsfiddle.net/syran/xL2EB/10/ 我从js-methods添加了array-0.9.js文件,这稍微解决了这个问题。它现在可以正确验证直到单选按钮的第一行项目,但在此时失败。如果我删除单选按钮检查,它将在num和maxlen验证的第二行失败。请检查小提琴以获取更新的代码,并添加第二行。
HTML代码:
<form name="checkvoid" method="post">
<table id="mytable" border="1">
<tbody>
<tr>
<td nowrap>Branch Number:
<input type="text" name="bid" value="1" size="3">
</td>
<td colspan="6">
<input type="submit" value="Submit Voided Checks">
</td>
</tr>
<tr>
<td align="center">Date</td>
<td align="center">Account #</td>
<td align="center">Serial #</td>
<td align="center">Amount</td>
<td>MO</td>
<td>CC</td>
</tr>
<tr class="check">
<td>
<select name="1[date][month]">
<option value="1">Jan</option>
<option value="2">Feb</option>
<option value="3">Mar</option>
<option value="4" selected>Apr</option>
<option value="5">May</option>
<option value="6">Jun</option>
<option value="7">Jul</option>
<option value="8">Aug</option>
<option value="9">Sep</option>
<option value="10">Oct</option>
<option value="11">Nov</option>
<option value="12">Dec</option>
</select>
<select name="1[date][day]">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29" selected>29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<select name="1[date][year]">
<option value="2012">2012</option>
<option value="2013" selected>2013</option>
</select>
</td>
<td>
<input type="text" name="1[actnum]" size="10" value="1">
</td>
<td>
<input type="text" name="1[serial]" size="10" value="1">
</td>
<td>$
<input type="text" name="1[amount]" size="10" value="1">
</td>
<td>
<input type="radio" name="1[type]" value="1" CHECKED>
</td>
<td>
<input type="radio" name="1[type]" value="2">
</td>
<tr>
<td colspan="6">
<input type="checkbox" name="certify" value="1">I certify that all the information above is correct.</td>
</tr>
</tbody>
</table>
<input type="hidden" name="action" value="process">
使用Javascript:
var frmvalidator = new Validator("checkvoid");
frmvalidator.addValidation("bid", "req", "Please enter your Branch Number!");
frmvalidator.addValidation("bid", "num", "Your Branch Number should be a Number!");
frmvalidator.addValidation("1[actnum]", "req", "Line #1: You must enter an account number!");
frmvalidator.addValidation("1[actnum]", "num", "Line #1: Your Account Number must be a number!");
frmvalidator.addValidation("1[actnum]", "maxlen=8", "Line #1: Your Account Number cannot exceed 8 numbers!");
frmvalidator.addValidation("1[serial]", "req", "Line #1: You must enter a serial number!");
frmvalidator.addValidation("1[serial]", "num", "Line #1: Your Serial Number must be a number!");
frmvalidator.addValidation("1[serial]", "maxlen=10", "Line #1: Your Serial Number cannot exceed 10 numbers!");
frmvalidator.addValidation("1[amount]", "req", "Line #1: You must enter an amount!");
frmvalidator.addValidation("1[amount]", "num", "Line #1: Your Amount must be a number!");
frmvalidator.addValidation("1[type]", "selone", "Line #1: You must select either Money Order or Cashier's Check!");
frmvalidator.addValidation("certify", "shouldselchk", "Your must certify that the form is correct!");
我没有在IE中使用数组工作:http://jsfiddle.net/syran/xL2EB/4/
答案 0 :(得分:1)
删除了包含名称属性值的[]
括号后,工作正常。
<input type="text" name="1[actnum]" size="10" value="1">
至<input type="text" name="1actnum" size="10" value="1">
你显然必须更新你的js以反映这一点。
答案 1 :(得分:1)
问题是由使用数字作为数据类型引起的。 IE不知道如何处理它。别人给了我那个小窍门,我能够通过创建一个2D阵列来修复它。
http://jsfiddle.net/syran/xL2EB/12/
stuff[#][fieldname]
frmvalidator.addValidation("stuff[1][actnum]", "req", "Line #1: You must enter an account number!");
答案 2 :(得分:1)
我有同样的问题,我改变了add_validation函数。 你可以将gen_validatorv4.js中的add_validation函数替换为:
function add_validation(itemname, descriptor, errstr)
{
var condition = null;
if (arguments.length > 3)
{
condition = arguments[3];
}
if (!this.formobj)
{
alert("Error: The form object is not set properly");
return;
}
var itemobj = this.formobj[itemname];
var i=0;
for (var key in itemobj)
{
i=parseInt(i)+1;
var errtmp="";
if(typeof(itemobj[key]) !="object" || itemobj[key]==null || itemobj[key].name==null ) continue;
if(itemobj[key].name.toString().indexOf("[]") >1 )
{
if (itemobj[key].length && isNaN(itemobj[key].selectedIndex))
//for radio button; don't do for 'select' item
{
// itemobj[key] = itemobj[key][0];
}
if (!itemobj[key])
{
alert("Error: Couldnot get the input object named: " + itemname);
return;
}
if (true == this.validate_on_killfocus)
{
itemobj[key].onblur = handle_item_on_killfocus;
}
if (!itemobj[key].validationset)
{
itemobj[key].validationset = new ValidationSet(itemobj[key], this.show_errors_together);
}
if(typeof(itemobj[key].validationset.add)=="function")
{
var errtmp=errstr.replace("{num}",i) ;
itemobj[key].validationset.add(descriptor, errtmp, condition);
itemobj[key].validatorobj = this;
}
}
else
{
var itemobj = this.formobj[itemname];
if (itemobj.length && isNaN(itemobj.selectedIndex))
//for radio button; don't do for 'select' item
{
itemobj = itemobj[0];
}
if (!itemobj)
{
alert("Error: Couldnot get the input object named: " + itemname);
return;
}
if (true == this.validate_on_killfocus)
{
itemobj.onblur = handle_item_on_killfocus;
}
if (!itemobj.validationset)
{
itemobj.validationset = new ValidationSet(itemobj, this.show_errors_together);
}
itemobj.validationset.add(descriptor, errstr, condition);
itemobj.validatorobj = this;
break;
}
}
}
&#13;