I am now running 4.0 RC3.21.
I have a form that uses a <select><option> tag set. I need to fill it from the database. That works fine. My problem is that I can't get the '
<option selected ...
option to work. So, debugger shows me this [option] => com_chronoforms
[chronoform] => edtheAcquiredStock
[acqToken] => 13
[Itemid] =>
[Acquired_Stock_ID] => 13
[idSpecies] => 12
[Source] => Noosa Landcare
[Date_Acquired] => 2011-01-26
[Qty_Acquired] => 3
[Remaining_Qty] => 0
[Comment] =>
And the selected value I need to trap is passed by that[idSpecies] field.
This is the code I am using to fill the ,select. tag.
function fillSpeciesSelectBox(){
//fb ('fillSpeciesSelectBox',FirePHP::INFO);
// build a query to list species
$db =& JFactory::getDBO();
$dbQuery ="SELECT id,Scientific_Name, Common_Name FROM #__RV_Species ORDER BY Scientific_Name, Common_Name";
// set the query
$db->setQuery($dbQuery);
//echo($dbQuery );
// load the data
$speciesRecords=$db->loadAssocList();
//print_r ($speciesRecords);
?>
<select size="1" style="width:400px;" label_over="0" hide_label="0" id="ididSpecies" name="idSpecies">
<?php
foreach ($speciesRecords as $aSpeciesRecord) {
?>
<option value="<?php echo $aSpeciesRecord['id'];?>"
</option><?php echo $aSpeciesRecord['Scientific_Name'].' "'.$aSpeciesRecord['Common_Name'].'"';
}
?>
</select>
<?php
return;
}
As I say - that fills the tag fine.
I had it in mind to use the data passed in that array to manually set the selected value (
if PassedValue == $aSpeciesRecord['id'] then add 'selected'
. But I can't work out how to get at that value PassedValue. The odd thing is that, if I refresh the window after the first load, then the correct selected value is 'marked'. I am thus wondering if there is something that I should do after filling that <select> tag to force the 'select' value.
Any help greatly appreciated.
Nick