In my attempt to incorporate client-side validation in Struts 2 with the xhtml
theme, I have encountered an issue. The JavaScript being generated is unable to validate my code. Upon further investigation, I discovered that Struts is using a specific notation to reference the elements.
form = document.getElementById(<form id>);
service = form.elements['service'];
The problem lies in the fact that 'service' is coming up as undefined
. When I checked, form.elements
turned out be null
; however, if I access the form using document.formname
, I am able to view the fields in the elements collection.
I have been pondering over whether document.forms[0]
returns the same object as document.getElementById(formid)
. Can someone explain the difference between the two?