Pages

Sunday, 6 April 2014

Jquery Not able to find Form by Name

I started out writing a form and at one point got stuck as the jquery that i wrote just refused to identify my form. The first thing i checked was the page source and it did have the form element.Now this was very strange as i was not able to retrieve the node no matter what i did.
When i checked the nodes for the element i could see that the form was missing, I was able to retrieve the parent as well as the child of this form.

Solution:
Added an id to the parent div of the form and then wrote the output to console using document.getElementById('parentDivId'), and I could see that the resulting html did not contain the form tag, but the view page source did show the tags. The issue was that the form that i was trying to access was actually wrapped around another form tag, thus the browser was ignoring this form node at runtime, hence it was appearing in page source but not in the actual run time DOM. Usually nesting a form tag gives an error on the jsp editor, but the reason why i was not able to catch this was because my child form was being added using a tag.

Conclusion:
Ensure that form tag is never nested. 

No comments:

Post a Comment