cancel
Showing results for 
Search instead for 
Did you mean: 

Java Script Needed

Former Member
0 Kudos

Hi,

My requirement is i have radio button group under that i have two radio buttons and under each radio butoon i have some 10 fields now my requirement is when a user selects first radio button only the fileds under first radio button should be enabled and the fields under second radio button should be disabled. when user selects second radio button only the fields under second radio button should be enabled and the fields under first radio button should be disabled.please provdie the java scripting and at what level should i write this scripting i mean at radio group level or where, kindly suggest.

Regards,

Venkat

Accepted Solutions (1)

Accepted Solutions (1)

vaibhav_tiwari
Contributor
0 Kudos

Hi Venkat,

Do the followng:

1. Create a radio button group:

-->Drag and drop one radio button UI element from library on to the form and again drag and drop a radio button UI element on to the form on the previous radio button. Two radio button in the same group will be created.

2. Write following code in the click event of the Radio button list created above.

if( this.rawValue == 0)
{
	TextField1.access = "";
	TextField2.access = "";
	TextField3.access = "readOnly";
	TextField4.access = "readOnly";
}

else if( this.rawValue == 1)
{
	TextField1.access = "readOnly";
	TextField2.access = "readOnly";
	TextField3.access = "";
	TextField4.access = "";
}

Here I have taken Textfields1,2,3,4 you can choose as many as you want. Set there access property to read only to set disable or ""(blank) to set enable as mentioned in the above code.

I hope it will work for you.

Regards,

Vaibhav Tiwari.

Former Member
0 Kudos

Hi,

i have taken a radio button group and in that i have two radio buttons, and under each radio button i have around 10 fields but here my doubt is how to identify these 10 fields belongs to first radio button and the other 10 fields belongs to second radio button is there any flag or some thing to identify the fields which belongs to which radio button. How can we differentiate the fields which belongs to first radio button or second radio button. For my requirement i have taken ISR_Radiobuttonlist which contains 2 radio buttons. Kindly suggest.

Regards,

Venkat.

vaibhav_tiwari
Contributor
0 Kudos

Hi Venkat,

Refer to my previous reply. There I have given 4 textfields. TextField1 and Textfield2 belong to radiobutton 1 and Textfield3 and Textfield4 belong to radiobutton 2. So you have to write the code for all the Textfields you take. Suppose you ahve 20 textfields 10 refer to radio button 1 and 10 refer to radio button2 Then use the code in following manner:

if( this.rawValue == 0)

{

TextField1.access = "";

TextField2.access = "";

.

.

.

.

TextField10.access = "";

TextField11.access = "readOnly";

TextField12.access = "readOnly";

.

.

.

.

.

TextField20.access = "readOnly";

}

else if( this.rawValue == 1)

{

TextField1.access = "readOnly";

TextField2.access = "readOnly";

.

.

.

.

TextField10.access = "readOnly";

TextField11.access = "";

TextField12.access = "";

.

.

.

.

.

TextField20.access = "";

}

I hope it will help you.

Regards,

Vaibhav Tiwari.

Former Member
0 Kudos

Vaibhav,

Thanks a lot it's working fine but with small problem.

Actually my requrement is text boxes as well as check boxes, under first radio button i have some check boxes and some text fields in the same manner under second radio button i have some text fields and check boxes.

(1) By default the first radio button is selected because in default values i have given like that. When i execute the form in output the first radio button will be selected as a default value. In this case i could able to check or uncheck the check box under first radio button as well as i could able to check or uncheck the check box under second radio button also. But actually in this case only check box under first radio button should be checked or unchecked and the check box under second radio button should be disabled.

(2) When i select the second radio button manually, from this time on wards the scripting that i have written as per your suggestion is working fine. In this case i could able to check or uncheck the check box under second radio button and the check box under first radio button is disabled. This is what i expected.

(3) Again when i select the first radio button manually, then i could able to check or uncheck the check box under first radio button and the check box under second radio button is disabled. This is what i expected.

(4) The problem is only for the first time, i could able to check or uncheck the check boxes under first radio button and second radio button, but when i start selecting the radio buttons manually it is working fine.

(5) I have written the following java scripting in click event on radio button group.

if (this.rawValue == 0)

{

ISR_CheckBox1.access = ""

ISR_CheckBox2.access = "readOnly"

}

else if (this.rawValue == 1)

{

ISR_CheckBox1.access = "readOnly"

ISR_CheckBox2.access = ""

}

Please suggest what might be the problem in this case, do i need to write the java script in any other event other than click event. Please suggest any help will be greatly appreciated.

Regards,

Venkat

vaibhav_tiwari
Contributor
0 Kudos

Hi Venkat,

Do the following:

1. Make all the fields below both the Radio buttons read Only by default.(To make them read only go to object palette-->value tab and choose type read only).

2. Write the following Java script code in the form:ready event of the form(top in the hierarchy).

if (RadioButtonList.rawValue == 0)
{
	TextField1.access = "";
        .
        .
        .
	TextField2.access = "";
}

Hope to solve your problem.

Regards,

Vaibhav Tiwari.

Answers (1)

Answers (1)

chintan_virani
Active Contributor
0 Kudos

Venkat,

Lets say you have radio button group called rbGrp, with two radio buttons and binding is set to values 1 and 2.

txt1 and txt2 are textfields to be enabled / disabled.

Now goto the change event for the rbGrp, and change the language to Javascript.

If first radio button is selected, value will be 1 and only txt1 should be enabled and txt2 should be disabled for user entry. For second radio button it should be vice-versa, here is sample code which does that

----- form1.#subform[0].rbGrp::change: - (JavaScript, client) --------------------------------------

xfa.host.messageBox("Value is : " + this.rawValue); // This will display the current value for selected Radio Button.

if(this.rawValue == 1)
{
	txt1.access = "open";
	txt2.access = "readOnly";
}
else if(this.rawValue == 2)
{
	txt1.access = "readOnly";
	txt2.access = "open";
}

Chintan