I understand what you are saying and the getElementsByName() is useful to know. An 
issue I still have is when 
writing the conditional javascript statement, I don't know where in the 
nested hierarchy I am in. What I am saying is that the conditional 
javascript statement needs to be coded once and be dynamic to know which 
hidden fields' value to set. To expand on my previous JSP code (I should 
have done this before:)

JSP code:
<nested: iterate property="myFirstArray">
        <nested: iterate property="mySecondArray">
                <input type="checkbox" name="myCheckBox" onchange="if 
(myCheckBox.checked) {myHidden.value='true';} else 
{myHidden.value='false';}" />
                <nested:hidden property="myHidden" />
        </nested:iterate>
</nested:iterate>

Is there a way I can ask the nested hierarchy what element I am iterating 
thru? Then I could do something like:
getElementsByName("myFirstArray[i].mySecondArray[ii].myHidden")[0].value="new 
value";

Perhaps this line <input type="checkbox" name="myCheckBox" onchange="if 
(myCheckBox.checked) 
{myHidden.value='true';} else {myHidden.value='false';}" /> would instead have to be a 
custom tag. In a custom tag can I get the 
current element # in the iteration? 

Any other thoughts? Thanks.

Zach

----- Message from "Slattery, Tim - BLS" <[EMAIL PROTECTED]> on Mon, 24 
May 2004 13:53:47 -0400 -----
To:
'Struts Users Mailing List' <[EMAIL PROTECTED]>
Subject:
RE: REPOST: nested hierarchy property and javascript

> HTML output code:
> <input type="checkbox" name="myCheckBox" onchange="if 
> (myCheckBox.checked) 
> {myHidden.value='true';} else {myHidden.value='false';}" /> 
> <input type="hidden" name="myFirstArray[0].mySecondArray[0].myHidden" 
> value="true" />

The value of the "name" attribute is just a character string to the DOM. 
So
access the element like this:

getElementsByName("myFirstArray[0].mySecondArray[0].myHidden")[0].value="new
value";


"getElementsByName" returns an array of elements whose "name" attribute
matches the supplied string (since "name" doesn't have to be unique in the
page). Assuming the "name"s in your page are unique, you access element 0 
of
that array. If there is more than one element with that convoluted name,
then you'll have to decide somehow which one you want.

--
Tim Slattery
[EMAIL PROTECTED]


I am struggling with using javascript to reference a nested property that 
is 2 levels deep. I didn't seem to find anything on this topic that helped 
me when searching the archive list. Here is an example of my code that is 
NOT working because document.forms[0].myHidden does not exist (it's in a 
nested hierarchy).

JSP code:
<input type="checkbox" name="myCheckBox" onchange="if (myCheckBox.checked) 
{myHidden.value='true';} else {myHidden.value='false';}" />
<nested:hidden property="myHidden" />

HTML output code:
<input type="checkbox" name="myCheckBox" onchange="if (myCheckBox.checked) 
{myHidden.value='true';} else {myHidden.value='false';}" />
<input type="hidden" name="myFirstArray[0].mySecondArray[0].myHidden" 
value="true" />

When the nested:hidden tag is output to the browser, its reference is 2 
levels deep in the nested hierarchy. I don't know how to account for that 
in my conditional javascript statement (myHidden.value='true'). Also, the 
position could be dynamic (i.e. 
name="myFirstArray[3].mySecondArray[4].myHidden).

Thanks for any assistance!

Zach



-----------------------------------------
The information contained in this communication (including any attachments hereto) is 
confidential and is intended solely for the personal and confidential use of the 
individual or entity to whom it is addressed.  The information may also constitute a 
legally privileged confidential communication.  If the reader of this message is not 
the intended recipient or an agent responsible for delivering it to the intended 
recipient, you are hereby notified that you have received this communication in error 
and that any review, dissemination, copying, or unauthorized use of this information, 
or the taking of any action in reliance on the contents of this information is 
strictly prohibited.  If you have received this communication in error, please notify 
us immediately by e-mail, and delete the original message.  Thank you

Reply via email to