Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

jakarta struts and javascript

Status
Not open for further replies.

lavalleeb

Programmer
Oct 18, 2005
4
US
I have a JSP page that uses struts tags for text fields, 2 radios and 5 checkboxes. The checkboxes need to be disabled depending on which radio is selected. I've attached onclick to each radio and have a javascript function in place. Problem is how to I reference an actionForm property in the javascript. I've tried document.forms[0].elements['accessDocumentSunday'].disabled = true;

with no success. I keep getting the error accessDocumentSunday is null or not a type.
 
Hi,

Is the checkboxes that you are trying to disable are a group or individual checkbox elements in the Form? How ever actionForm property is the name of the check box element.

Below is the example which is in pure html accessDocumentSunday is a group.

Code:
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<SCRIPT LANGUAGE="JavaScript">
<!--
function test(arg){
 var chkLen = document.forms[0].elements['accessDocumentSunday'].length;
 if(arg.value == 'yes')
 {
   for(var i=0; i<chkLen; i++){
     document.forms[0].elements[i].disabled = true;
   }
 }else if(arg.value == 'no'){
    for(var i=0; i<chkLen; i++){
     document.forms[0].elements[i].disabled = false;
   }
 }

 //document.forms[0].elements['accessDocumentSunday'].disabled = true
}
//-->
</SCRIPT>
</HEAD>

<BODY>
<FORM METHOD=POST ACTION="">
One <INPUT TYPE="checkbox" NAME="accessDocumentSunday">
Two <INPUT TYPE="checkbox" NAME="accessDocumentSunday">
<INPUT TYPE="text" NAME="one">
<br>
Yes<INPUT TYPE="radio" NAME="tst" value="yes" onClick="test(this)">
No<INPUT TYPE="radio" NAME="tst"  value="no" onClick="test(this)">
</FORM>
</BODY>
</HTML>

Cheers
Venu
 
Venu:

Thank you for responding to my question "Jakarta Struts and Javascript". Here is my javascript sample:

function disableField()
{
var form = document.forms[0];
document.forms[0].elements['allowAccessSunday'].disabled = true;
}
and here is my jsp code:

<tr>
<td width=1%>&nbsp;</td>
<td width="19%"><bean:message key="app.accessRestrictions" />&nbsp;<font color="#ff0000">*</font></td>
<td valign="bottom" width="80%"><html:radio property="accessRestricted" name="ModifySchoolUserForm"
value="false" onclick="disableField()" /><bean:message key="app.noRestrictions" /> </td>
</tr>

actionForm is a formBean in Struts that contains the data for each field element in the jsp including the checkboxes. In this example, I click the radio button called accessRestrictions and that calls the disableField() javascript function. I want the javascript function to then disable the checkbox called access 'allowAccessSunday'. the checkbox code is below:

<td width="21%"><html:checkbox property="allowAccessSunday" disabled="false" />
<span class="style2"><bean:message key="app.sunday" /></span></td>

As you can see both the radio and checkbox are using the struts taglib and 'accessRestrictions' and 'allowAccessSunday' are both defined fields in a bean.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top