File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes getElementById not working in IE9 for bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "getElementById not working in IE9 for bean" Watch "getElementById not working in IE9 for bean" New topic
Author

getElementById not working in IE9 for bean

Helene Prince
Greenhorn

Joined: Jun 27, 2012
Posts: 4
I am testing our application with IE9. We have code that works in IE7 but it's not working with IE9.

<jsp:useBean id="someForm" class="org.abc.desktop.form.someForm" scope="request" />

var elea = document.getElementById('someForm');

In IE9, getElementById is returning null.

I'm not a javascript expert, but I've been trying to research this all day. Does anyone have any ideas why this stopped working in IE9 or how to resolve?

Thanks for any help!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61202
    
  66

Showing us the server-side markup is not helpful. What is the HTML that is generated from this? That's all that JavaScript is going to see, and all you should be looking at to diagnose this.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Helene Prince
Greenhorn

Joined: Jun 27, 2012
Posts: 4
The HTML that is generated for the bean is <form name="someForm" method="post" action="/UpdateSomeFormAction" onsubmit="return checkSubmit();">

I figured out a solution by using the method getElementsByName, but I would rather not have to do this (lots of places to change the code). Since IE9 changes the id to name, is there anyway to assign an id tag? I've played around with various options, but nothing seems to work.

<jsp:useBean id="someForm" class="org.abc.desktop.form.someForm" scope="request" />

I'm farily new to javascript (inheriting work from others), but I'm learning as I go. Thanks for your help!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61202
    
  66

Helene Prince wrote:Since IE9 changes the id to name, is there anyway to assign an id tag?

IE( does not change anything. It's the server-side markup that's generating the HTML that's sent to the browser. The browser has absolutely nothing to do with it.

So what markup is being used to generate the form tag? That's where the problem lies.

I'm farily new to javascript

This is not a JavaScript issue. It's just that the JavaScript is revealing a problem with the server-side markup, which is not generating the id attribute for the form tag.

P.S. The <jsp;useBean> markup is not what is generating the form tag -- what is?
Helene Prince
Greenhorn

Joined: Jun 27, 2012
Posts: 4
If my understanding is correct, the form is created through the struts-config.xml file. I attempted to add an id tag there, but it didn't solve my problem. I guess I will stick with using the getElementsByName method since it's working, but at least I now have a much better understanding of the issue.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61202
    
  66

Helene Prince wrote:If my understanding is correct, the form is created through the struts-config.xml file.

Your understanding is not correct. The HTML form tag is likely generated by a struts tag in your page.

I attempted to add an id tag there, but it didn't solve my problem

Of course not. That has nothing to do with the issue.

I guess I will stick with using the getElementsByName method since it's working, but at least I now have a much better understanding of the issue.

Based on the above, I'd say you need to investigate this issue more because you do not have a good grasp of what's going on.

I suggest finding out where the form tag is being declared and actually fixing the problem rather than slapping a band-aid on it.
Helene Prince
Greenhorn

Joined: Jun 27, 2012
Posts: 4
You are correct that I don't understand everything about struts, but I do know that the form and action class is declared in the struts-config.xml file. The JSP references the action class.... so the struts tag in my page is
<html:form action="UpdateSomeAction" onsubmit="return checkSubmit();">

From the strut-config.xml file, the form and action is declared as:

<form-beans>
<form-bean name="someForm"
type="org.abc.desktop.form.someForm" />

<action path="/UpdateSomeAction"
type="org.abc.action.UpdateSomeAction"
name="someForm"
scope="request" />
</action>


Since the form name and class are declared in the struts-config.xml file, this is where I added the id tag, but it didn't solve my problem. I don't want to slap a band-aid on this to fix it, that's why I'm trying to research the problem. However, time is money and there is a limited supply of time and money sometimes.

I don't easily give up... so I'm still researching and trying to gain a better understanding as I go. Your suggestions have helped tremendously because it helped me to think/look in other directions, so I appreciate all your help!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61202
    
  66

Nowhere in your <html:form> tag do you give an id value to the HTML form!

You are confusing the HTML form with the bean that holds the form values. They are not the same!

At this point I'm going to move this to the Struts forum.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getElementById not working in IE9 for bean