How to set a default value for a radiobutton?

mirceat

Member
Hello,

I'm using the "Advanced" option for a radiobutton element in order to create some options, but I need to set a default value and I don't know what attributes should I add in order to set an option as "selected". This is my code:

PHP:
$db = JFactory::getDbo();
$db->setQuery("SELECT valoare_camp_ro FROM contracts_tool_setari_6_repeat where alocare_grup = 9 and format_camp = 11");
$rows = $db->loadResult();
$valori = explode("|",$rows);
foreach ($valori as $valoare) {
list($id,$text) = explode("~",$valoare);
if (!isset($id)){
$id = $text;
}
$options[] = JHTML::_('select.option', trim($id), trim($text)); <--what other attributes can I have here?
}
return $options;

The string retrieved from database looks like this, I want to set default selected value to be 1:
1~E-mail sau hartie|2~Integral pe hartie

Thank you
 
upload_2023-12-6_16-6-6.png
so maybe JHTML::_('select.option', trim($id), trim($text),trim($id));
 
same as above; I tried also with 1 as static value, 'selected=1' and 'selected=true', options are not displayed anymore:

$options[] = JHTML::_('select.option', trim($id), trim($text),'selected=1');
 
that 4th option is setting it disabled. The fabrik code does not handle a selected option so the only way to set a default is via javascript. Make sure you test for a new record before you do this.
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top