Expand my Community achievements bar.

Write numbers to a text box when radio button is clicked

Avatar

Level 1

I have a very simple form, part of which has a series of radio buttons that allow the client to choose options. What I have been attempting to do is configure the check boxes so that when a radio button is selected, a number would be written to a blank, invisible number field. All the invisible number fields would then be added up as part of the totals.

What I can't seem to figure out is how to write information to another field when a radio button is clicked. Has anyone here ever tried that?

7 Replies

Avatar

Former Community Member

You woudl put code on teh RadioButton Group ...not the radioButton object. I woudl use the change event and write something like this:

if (this.rawValue == 1){

     //The radio button is on

     NameofHiddenField.rawValue = NameofHiddenField + number you want to set

} else {

     //The radio button is off

     NameofHidddenField.rawValue = NameofhiddeField - number you want to set

}

Hope that helps

Paul

Avatar

Level 1

I can see where you are going with this: One thing I need clarification on though...

When I select the Radio Button Group itself I get

form1.#subform[0].RadioButtonList[2].scrapbookYES::mouseUp - (JavaScript, client)

form1.#subform[0].RadioButtonList[2].#field[1]::mouseUp - (FormCalc, client)

In this case, where would I place the code you suggested?

Avatar

Level 1

pguerett,

Your code seems to work with one exception: I have it working so a number is populated in the invisible field. Now the problem is, if the radio button is not checked, the number stays.

Avatar

Former Community Member

So that is in the else portion of the if statement. You woudl basically do the reverse that you did to add the number. You could set the field.rawValue = 0

Paul

Avatar

Level 1

We are very close!

What you suggested is working. One unfortunate side effect is that the radio buttons do not show anything inside them when they are clicked. Here is an example:

form1.#subform[0].RadioButtonList[3].propboxYES::mouseUp - (JavaScript, client)

if

(this.rawValue = 1){

//The radio button is on

propbox.rawValue

= 50

}

form1.#subform[0].RadioButtonList[3].propboxNO::mouseUp - (JavaScript, client)

if

(this.rawValue =1){

//The radio button is on

propbox.rawValue

= 0

}

With the code above, its making the proper entry in the invisible box "propbox" when either YES or NO radio buttons are clicked in this case. I am not sure why the checks are not showing in the circles though. Any ideas?

Avatar

Former Community Member

The command with the if statement needs two equal signs ==. A single equal means that you are putting the value 1 into the field and the == sign means that you want to compare the value of the radio button to the value 1.

Paul

Avatar

Level 1

Gotcha!

I think the reason why I altered that part in the first place was that when there was "==" in place, the check boxes worked, but when I clicked NO, the number would not be changed to 0. I am not sure why.