views:

41

answers:

1

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 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?

A: 

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.

BalusC