aspose file tools
The moose likes Struts and the fly likes How to disable html:checkbox based on  html:radio selection Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Reply Bookmark "How to disable html:checkbox based on  html:radio selection" Watch "How to disable html:checkbox based on  html:radio selection" New topic
Author

How to disable html:checkbox based on html:radio selection

Shodhan Shah
Greenhorn

Joined: Apr 27, 2006
Posts: 18
Guys

I need to disable html:checkbox based on selection of html:radio.

Here is my componenets in JSP.
Basically I want to disable ( not allow user to check this checkbox) html:checkbox when html:radio has value "instruction" (second radio button).
Any Idea? Thanks in advance.


<td class="tableHeadingOne" align="right" valign="middle">
Type :<html:radio property="type" value="account" >Account</html:radio>
<html:radio property="type" value="instruction" >Instruction</html:radio>
</td>


<td align="left" valign="middle"><html:checkbox property="reply" />
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
To handle the default values, or values retrieved from the database before this page is displayed, you can set it like this:

<html:checkbox property="reply" disabled="${myForm.type == 'instruction'}" />

The above assumes you're using the Struts-el version of the tags.

To change the disabled status dynamically based on the choice made by the user you will need to use javascript. Something like this:

Type :<html:radio property="type" value="account" onklick="document.myForm.reply.disabled = false">Account</html:radio>
<html:radio property="type" value="instruction" onklick="document.myForm.reply.disabled = true">Instruction</html:radio>

onklick is used above instead of onclick to get around the JavaRanch filter. Also substitute the actual name of the form-bean name used by this page for "myForm".
[ May 25, 2006: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
Shodhan Shah
Greenhorn

Joined: Apr 27, 2006
Posts: 18
Thanks for your reply.
I tried following as suggested by you.

<html:radio property="type" value="account" onKlick="document.notifyBrowserForm.reply.disabled = false">Account</html:radio>

<html:radio property="type" value="instruction" onKlick="document.notifyBrowserForm.reply.disabled = true">Instruction</html:radio>

but I am getting javascript error.
'document.notifyBrowserForm is null or not an object '

Looks Like my form name (notifyBrowserForm) is wrong. What should my form name

My form is html:form.
<html:form action="/services/notifyBrowser" focus="msgSessionID" >
( which contains both radio buttons and check box)
and it is associated with notifyBrowserForm in struts-config.xml.
<struts-config>
<form-beans>
<form-bean name="notifyBrowserForm"
type="com.lehman.enaf.mwgui.NotifyBrowserForm" />
Shodhan Shah
Greenhorn

Joined: Apr 27, 2006
Posts: 18
sorry
I am getting javascript error
'document.notifyBrowserForm.reply' is null or not an object
Shodhan Shah
Greenhorn

Joined: Apr 27, 2006
Posts: 18
Never mind . I got it worked.
THANKS FOR ALL YOUR HELP.
Instead of "document.notifyBrowserForm.reply.disabled = false" I put only
"reply.disabled = false". and it works.
I know this is not 100% correct but for now it works.

THANKS a LOT
Shodhan Shah
Greenhorn

Joined: Apr 27, 2006
Posts: 18
Merril

I need little modifications.


html:radio property="type" value="account" onklick="reply.disabled = false">Account</html:radio>
<html:radio property="type" value="instruction" onklick="reply.disabled = true">Instruction</html:radio>


<td align="left" valign="middle"><html:checkbox property="reply" />



The above works ( disable/enable check box based on radio button value) only when we click on radio button.

What if we want to disable/enable checkbox based on current value of radio Button ( i.e. not only on onKlick event but based on existing value of radio button)

If I click on 'instruction' radio button , check box is disabled as desired.
But when I submit form ,it gets 'enable' mode though radio button value is 'instruction'.

So how to enable /disable checkbox based on current value of radio button ( not only upon onKlick event) .


Thanks in advance.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
If you'll look carefully at my first post, you'll see that I have already shown you some code for doing this:

<html:checkbox property="reply" disabled="${myForm.type == 'instruction'}" />

Note that the above will only work if you are using the EL version of the Struts tags. (See this link for more information) If you're not, you will need to use a scriptlet <%= %> instead.
[ May 31, 2006: Message edited by: Merrill Higginson ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to disable html:checkbox based on html:radio selection
 
Similar Threads
checkbox values
logic:forward problem
This has to be easy! Arraylist?
problem in html:image
Problems with select