开发者

struts validation problem in IE

I am using Struts 2.1.8 and facing validation problem in IE. I am getting the following error

An exception occurred: Error. Error message: Invalid argument. 

I tried out to figure out the cause and found the following. My generated javascript code is:

field = form.elements['district.name'];  
var error = "Enter only alphabets for开发者_StackOverflow社区 district";  
if (continueValidation && field.value != null && !field.value.match("^[a-zA-Z ]*$")) {  
    addError(field, error);  
    errors = true;  
}  

I tried to mock up by putting the same code in a function and calling it in onclick event. The method addError() throws the exception and the reason is field variable. If I change it to field[0], it works fine. How to fix this error?


Check the generated HTML source. Open the page in webbrowser, rightclick and choose View Source. Is the input field's name really district.name? Isn't it prefixed/suffixed with some other autogenerated key (possibly the ID/name of the <form>) like as many other MVC frameworks do? If so, you'll need to change the JavaScript code accordingly that it uses the right element name as it appears in the HTML DOM tree. You know, JavaScript runs at the client machine and only sees the generated HTML DOM tree, not the "original" server-side code which is responsible for generating the HTML.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜