Hi Doug,

We do something similar, but with a check box and an input field, but the
process should be the same.


Javascript function that enables the input field based on the checkbox
accessed by form and index

function isBudgetRequired(form, index) {
  checkBox = eval(form.elements["costElement[" + index + "].selected"]);
  budgetInput = eval(form.elements["costElement[" + index +
"].budgetInputDisplay"]); 
  if (checkBox.checked) {
    budgetInput.disabled = false;
  }  
  else {
    budgetInput.disabled = true;
  } 
}

JSP code snippet
           <strutslogic:iterate id="data"
                                indexId="idx"
                                name="ouActivityDetailForm"
                                property="list">
             <tr>
               <td width="50" align="center">
                 <strutshtml:checkbox property="<%= "costElement[" + idx +
"].selected" %>" 
                                      onclick="<%=
"isBudgetRequired(this.form, " + idx + ")" %>" />
               </td>
               <td width="70" align="right">
                  <strutsbean:define id="checked" 
                                     name="ouActivityDetailForm" 
                                     property="<%= "costElement[" + idx +
"].selected" %>" /> 
                  <strutshtml:text name="ouActivityDetailForm"
                                   property="<%= "costElement[" + idx +
"].budgetInputDisplay" %>"
                                   size="6"
                                   disabled="<%=
!((Boolean)checked).booleanValue() %>" />
               </td>
             </tr>  
           </strutslogic:iterate>


Les Wilson

Shell Finance Services
Shell International Limited, Shell Centre, London SE1 7NA, United Kingdom

Tel: +44 20 7934 6463 Other Tel: +44 7974 948877
Email: [EMAIL PROTECTED]
Internet: http://www.shell.com


-----Original Message-----
From: Doug Mclellan [mailto:[EMAIL PROTECTED]]
Sent: 13 May 2002 17:51
To: Struts Users Mailing List
Subject: RE: Using onclick within iterate tag


Hi again,

The form I am using extends the basic ActionForm class.

-----Original Message-----
From: James Mitchell [mailto:[EMAIL PROTECTED]]
Sent: 13 May 2002 17:49
To: Struts Users Mailing List
Subject: RE: Using onclick within iterate tag


Ok, then you will probably be needing to use indexed properties.

I am trying to gather a bit of "working code" for you.

I should be finished shortly.

In the meantime, take a look at using indexed properties.  Also, are you
using the DynaActionForm???

JM




> -----Original Message-----
> From: Doug Mclellan [mailto:[EMAIL PROTECTED]]
> Sent: Monday, May 13, 2002 12:43 PM
> To: Struts Users Mailing List
> Subject: RE: Using onclick within iterate tag
>
>
>
> You have hit the nail on the head.
>
> Doug
>
> -----Original Message-----
> From: James Mitchell [mailto:[EMAIL PROTECTED]]
> Sent: 13 May 2002 17:42
> To: Struts Users Mailing List
> Subject: RE: Using onclick within iterate tag
>
>
> Ok, so you want to disable the second box (by default) and then if the
> user
> selects the first box, then allow the second to be selected.  And this
> is
> all done over and over again in a list of contacts.
>
> ????
>
>
> JM
>
> > -----Original Message-----
> > From: Doug Mclellan [mailto:[EMAIL PROTECTED]]
> > Sent: Monday, May 13, 2002 12:31 PM
> > To: Struts Users Mailing List
> > Subject: RE: Using onclick within iterate tag
> >
> >
> >
> > What I am using the JSP to do is display the list of my personal
> > contacts.
> >
> > So I am using the iterate tag to retrieve the list of personal
contact
> > objects from my Form bean. Within the iterate tag I display the name
> > etc. The two checkbox tags on each row of the table are used to set
> one
> > or more of the returned contacts to a supervisor and if so enable
the
> > other checkbox to lock the contact's account.
> >
> > So I need the checkbox tags to be within the iterate tag.
> >
> > Thanks again James for taken time out to answer my question, its
much
> > appreciated.
> >
> > Doug
> >
> > -----Original Message-----
> > From: James Mitchell [mailto:[EMAIL PROTECTED]]
> > Sent: 13 May 2002 17:07
> > To: Struts Users Mailing List
> > Subject: RE: Using onclick within iterate tag
> >
> >
> > I guess I need a bit more info to properly answer/stab-at your
> question.
> >
> > I assume that you know what the two checkboxes will always be.
> > -Why not just put the two on your jsp and not iterate over them.
> >
> > Or for a more generic approach, say you are writing your own custom
> > taglib
> > like.....
> >
> > <myapp:conditionalCheckbox property="MyMapOfChecks">
> >
> > or something like that........and this taglib would write out the
html
> > necessary to make the second box (or more) disabled/enabled based on
> the
> > 1st
> > value.
> >
> >
> >
> > Am I way off here???
> >
> >
> >
> > JM
> >
> > > -----Original Message-----
> > > From: Doug Mclellan [mailto:[EMAIL PROTECTED]]
> > > Sent: Monday, May 13, 2002 11:56 AM
> > > To: Struts Users Mailing List
> > > Subject: RE: Using onclick within iterate tag
> > >
> > >
> > > Sorry,
> > >
> > > I meant the position within the iterator. Within the JSP there is
> two
> > > checkbox tags for each iteration and I need to only enable the
> second
> > > checkbox if the first has been checked.
> > >
> > > Doug
> > >
> > > -----Original Message-----
> > > From: James Mitchell [mailto:[EMAIL PROTECTED]]
> > > Sent: 13 May 2002 16:53
> > > To: Struts Users Mailing List
> > > Subject: RE: Using onclick within iterate tag
> > >
> > >
> > > When you mean "position" do you mean "position within the
iterator"
> or
> > > "position on the page"???
> > >
> > > JM
> > >
> > > > -----Original Message-----
> > > > From: Doug Mclellan [mailto:[EMAIL PROTECTED]]
> > > > Sent: Monday, May 13, 2002 11:47 AM
> > > > To: Struts Users Mailing List
> > > > Subject: RE: Using onclick within iterate tag
> > > >
> > > >
> > > > Hi again,
> > > >
> > > > Many thanks James for helping us out, that works great.
> > > >
> > > > Apologies for not asking the question properly first time
around.
> > But
> > > is
> > > > it possible to also pass the position of the checkbox that has
> been
> > > > clicked so that the JavaScript function could be used to control
> > other
> > > > checkbox tags within the iterate tag.
> > > >
> > > > Thanks again.
> > > >
> > > > Doug
> > > >
> > > > -----Original Message-----
> > > > From: James Mitchell [mailto:[EMAIL PROTECTED]]
> > > > Sent: 13 May 2002 16:10
> > > > To: Struts Users Mailing List
> > > > Subject: RE: Using onclick within iterate tag
> > > >
> > > >
> > > > try this...
> > > >
> > > >
> > > > <html:checkbox property="checkBox1"
> > > > onclick="JavaScript:handleCheckbox(this)"/>Check 1<br>
> > > > <html:checkbox property="checkBox2"
> > > > onclick="JavaScript:handleCheckbox(this)"/>Check 2<br>
> > > > <html:checkbox property="checkBox3"
> > > > onclick="JavaScript:handleCheckbox(this)"/>Check 3<br>
> > > > <html:checkbox property="checkBox4"
> > > > onclick="JavaScript:handleCheckbox(this)"/>Check 4<br>
> > > >
> > > > <SCRIPT LANGUAGE=javascript>
> > > > <!--
> > > > function handleCheckbox(obj){
> > > >   alert(obj.name);
> > > >
> > > > }
> > > > //-->
> > > > </SCRIPT>
> > > >
> > > > JM
> > > >
> > > > > -----Original Message-----
> > > > > From: Doug Mclellan [mailto:[EMAIL PROTECTED]]
> > > > > Sent: Monday, May 13, 2002 10:31 AM
> > > > > To: [EMAIL PROTECTED]
> > > > > Subject: Using onclick within iterate tag
> > > > >
> > > > >
> > > > >
> > > > > Hi,
> > > > >
> > > > > I am using onclick event handler on a checkbox tag within a
> > iterate
> > > > tag,
> > > > > since there is going to be multiple checkbox tags can someone
> > please
> > > > > tell me how I can pass the identifier of the checkbox that has
> > fired
> > > > the
> > > > > onclick event to the JavaScript function specified in the
> onclick.
> > > > >
> > > > > Thanks.
> > > > >
> > > > >  Doug
> > > > >
> > > > > --
> > > > > To unsubscribe, e-mail:
> > > > > <mailto:[EMAIL PROTECTED]>
> > > > > For additional commands, e-mail:
> > > > > <mailto:[EMAIL PROTECTED]>
> > > > >
> > > > >
> > > >
> > > >
> > > > --
> > > > To unsubscribe, e-mail:
> > > > <mailto:[EMAIL PROTECTED]>
> > > > For additional commands, e-mail:
> > > > <mailto:[EMAIL PROTECTED]>
> > > >
> > > >
> > > > --
> > > > To unsubscribe, e-mail:
> > > <mailto:[EMAIL PROTECTED]>
> > > For additional commands, e-mail:
> > > <mailto:[EMAIL PROTECTED]>
> > >
> > >
> > >
> > > --
> > > To unsubscribe, e-mail:
> > > <mailto:[EMAIL PROTECTED]>
> > > For additional commands, e-mail:
> > > <mailto:[EMAIL PROTECTED]>
> > >
> > >
> > > --
> > > To unsubscribe, e-mail:
> > <mailto:[EMAIL PROTECTED]>
> > For additional commands, e-mail:
> > <mailto:[EMAIL PROTECTED]>
> >
> >
> >
> > --
> > To unsubscribe, e-mail:
> > <mailto:[EMAIL PROTECTED]>
> > For additional commands, e-mail:
> > <mailto:[EMAIL PROTECTED]>
> >
> >
> > --
> > To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
>
>
>
> --
> To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
>
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>



--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to