1
votes

I need to set the value of a Radio Button Group that has two possible values. I'm able to accomplish this with SSJS, but having issues setting it via CSJS. Any help is appreciated.

2

2 Answers

6
votes

I use something like this:

function setRadioValue(value)
{
    var elements = document.getElementsByName ("#{id:radioGroup1}");
    for(i=0;i<elements.length;i++) {
        if (elements[i].value == value) {
            elements[i].checked = true;
        }
    }
}

Then you can just call setRadioValue("This is teh value of the Radio Button I want to set")

Thanks

4
votes

You need to get the the server-side generated name of the radio button group using the #{id:} method. Example:

var radioButtonGroup = XSP.getElementById("#{id:radioButtonGroupName}");

You can then use client-side Javascript to manipulate the radioButtonGroup element. I believe you need to loop over the radio buttons in the elements until you find the radio button with the desired value. You can then set its checked value to true.