Help with "eval populate" in dropdown element

Status
Not open for further replies.

jfquestiaux

Well-Known Member
This is the first time I use this feature, so I need some help:

I need to generate a certain amount of options based on some outside condition: 1 to a value that a retreive in the URL.
This part is easy.
I then generate the expected values in the "eval populate" window.
I can come up with the following string ("4" being the value I retreived):
PHP:
$options = "JHTML::_('select.option','1','Room 1'),JHTML::_('select.option','2','Room 2'),JHTML::_('select.option','3','Room 3'),JHTML::_('select.option','4','Room 4')";

If I manually copy the value of the string in
PHP:
return array(JHTML::_('select.option','1','Room 1'),JHTML::_('select.option','2','Room 2'),JHTML::_('select.option','3','Room 3'),JHTML::_('select.option','4','Room 4');

I get the expected dropdown.
But how should I write the "return" line so it works on its own?
I tried
PHP:
return array($options);
but it's not working.
 
you wouldn't want a string - just an array of select.options, so:

PHP:
$options = array();
$options[] = JHTML::_('select.option','1','Room 1');
 
.....
 
 
return $options;
 
I was guessing that was the direction, but I still have a syntax problem since I am calculating the values in a for loop:
PHP:
for($i=1;$i<=$rooms;$i++){
    $options[] = JHTML::_('select.option',' . $i . ','Room  . $i . ');
}

This returns "Room . $i ." in the dropdown and I am confused on how to write this line.
 
Well silly me!
The correct line is
PHP:
$options[] = JHTML::_('select.option', $i,'Room ' . $i);

Thanks Troester.
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top