Merril, your following directions really helped. THANK YOU!
>I prefer using the actual name of the form, which in Struts is what you >specified as the name attribute of the action mapping in your struts->config.xml file. Exmple: >document.myForm.adminaction.value="xyz"
Even though it was first and only form in jsp, and even though I am not using tiles, for some reason, forms did not set values. After changing to the form name, everything is working as expected. For some reason same code (i.e. with forms) is working in other jsp correctly. But for safety there too I will introduce form name.
I firmly believe in the Extreme Programming principle of "Do the simplest thing that could possibly work." (DTSTTCPW). In a case like this where it's not important to make the code reusable (after all, it's just a simple one-statment event handler), the simplest thing is to write "document.myform.myproperty.value='xyz'". It's simple and it works on all browsers.
I would agree that it's not good code to put in a function, because the form name and property are hard coded. In this case, you'd want to use the other construct. Example:
[ May 10, 2007: Message edited by: Merrill Higginson ]
Originally posted by Garrett Smith: 2. document.getElementsByName( "inputName" ).value = "test";
The above code will result in an error. getElementsByName always returns an array, even if there is only one element by that name. It will work if changed to:
Joined: Jun 27, 2002
Edited my post. Thanks.
IE behavior: Returning named elements whose name attribute matches the argument in getElementById. ID must be unique, name is not unique. When IE gets more than 1 element with the same ID, it creates an collection.
getElementsByName returns a NodeList not an Array. There is a big difference. [ May 12, 2007: Message edited by: Garrett Smith ]
Joined: Feb 08, 2006
Lately I have been thinking that the getElementById method is the way to go. The worst part is that you have to add a styleId to each Struts tag, and make sure you test in a non-IE browser. I mention prototype (which I have only played around with) because it reduces "document.getElementById('phone')" to "$('phone')" and "document.getElementById('phone').value" to "$V('phone')"