selected option in a group radio

Hi,

I have a Radio Button Group with two choices, when a click event for example, I want to check for each option, if “ON” is selected call treatment 1, else if “OFF” is selected call another treamtment 2.

Radio-Button Group ID : htmlSelectOneRadio
Individual option 1 ID : optOn
Individual option 2 ID : optOff

The value and Item value for the 2 Individual options are empty.

something like this :


var radioGroupModel = CAF.model("#{caf:cid('htmlSelectOneRadio')}");    
var itemOn = radioGroupModel.get('optOn');
var itemOff = radioGroupModel.get('optOff');

if (itemOn.selected() == true) {  
    treatment1();
}
if (itemOff.selected() == true) {  
    treatment2();
}

the code return null.

if you have an idea how to do it.

Thanks

I’m not sure what code would return null there (there’s no return statement) but you’re calling a nonexistent method to see whether or not the item is checked.

Either (in Javascript) do this:

if (itemOn.checked) { 

Or using CAF.Model [pdf], do this:

if(isSelected(itemOn)) 

Either way notice you don’t have to put if( == true) - your test is a boolean, so just do this: if().

Hi Rob,

Thanks for your response :slight_smile:
I test the code, but it doesn’t work :frowning:
No message is alerted whn I click on one of the 2 options


var radioGroupModel = CAF.model("#{caf:cid('htmlSelectOneRadio')}");    
var itemOn = radioGroupModel.get('optOn');
var itemOff = radioGroupModel.get('optOff');

if(isSelected(itemOn))  {  
    alert("On !!");  
}

if (itemOff.checked) { 
    alert("Off !!");  
}

Get the index of a item in the radio group:
http://techcommunity.softwareag.com/ecosystem/documentation/webmethods/wmsuites/wmsuite8-2_sp2/My_webMethods/8-2-SP1_CAF_JavaScript_Reference/CAF.Select.Model.html#indexOf

Check if the item is selected:
http://techcommunity.softwareag.com/ecosystem/documentation/webmethods/wmsuites/wmsuite8-2_sp2/My_webMethods/8-2-SP1_CAF_JavaScript_Reference/CAF.Select.Model.html#isSelected

So your script should be something like this:

var radioGroupModel = CAF.model("#{caf:cid('htmlSelectOneRadio')}");    
var itemOnIdx = radioGroupModel.indexOf('optOn');
var itemOffIdx = radioGroupModel.indexOf('optOff');

if(radioGroupModel.isSelected(itemOnIdx))  {  
    alert("On !!");  
}

if (radioGroupModel.isSelected(itemOffIdx)) { 
    alert("Off !!");  
}

Thanks Eric,

The code is very logic, but when i click nothing happens, no alert !! ( i tested in chrome and IE)

Do I have to set the item value or value of the 2 options ? or change the javascript event ?

Thanks & regards

Yes, the indexOf call is matching the ‘Item Value’ of the item, so your ‘Options’ need an Item Value

Coool, tested and worked fine :slight_smile:

thanks man :wink:

Thank you for this post. It was very helpful for me.
Regards,