How to create a drop down list with select tag

1,166 views
Skip to first unread message

pierrehs

unread,
Nov 18, 2011, 6:37:05 PM11/18/11
to php-form-builder-class
Hello,
I wonder how I can create a drop down list with the ages values.
So select the two fields next to each other and with the value of from
18 to 98.

I have not managed to do it with PFBC.
Can you show me an example.
Thank you

pierrehs

unread,
Nov 18, 2011, 6:39:27 PM11/18/11
to php-form-builder-class
You can see an example on this image http://s10.postimage.org/6atb4aiad/select_option.jpg
of what I want to do.

Andrew Porterfield

unread,
Nov 18, 2011, 10:12:50 PM11/18/11
to php-form-bu...@googlegroups.com
Do you need an age range w/multiple select boxes? or just a single select box with options from 18 up to 98? The image you provided is very small and I can't really see what you're wanted to do.

- Andrew

pierrehs

unread,
Nov 19, 2011, 5:28:41 PM11/19/11
to php-form-builder-class
Sorry,
Here is a larger image http://s10.postimage.org/r7pj8ygbb/select_option.png

On Nov 19, 4:12 am, Andrew Porterfield <aporterfi...@imavex.com>
wrote:

Andrew Porterfield

unread,
Nov 19, 2011, 9:03:21 PM11/19/11
to php-form-bu...@googlegroups.com
There's not really a great way of doing what's shown in that picture within this project. You could always use the HTML element and just manually build the required <select> boxes. If it were me. I would use a single select box with options like…

18 - 25 years
26 - 35 years
etc

- Andrew

DeepCell

unread,
Nov 19, 2011, 11:14:22 PM11/19/11
to php-form-builder-class
Try this:

$age = array();
$age[] = "Choose Age";
for ($i=18;$i<=98;$i++)
{
$age[] = $i;
}

$form->addElement(new Element_Select("Age: ", "Age", $age,
array( "width" => "20" ) ));

I hope this help you!

Andrew Porterfield

unread,
Nov 20, 2011, 2:35:39 PM11/20/11
to php-form-bu...@googlegroups.com
Here's another version worth trying…

$select = '<select name="AgeRange[]"><option value="">--Select Age--</option>';
for($a = 18; $a <= 98; $a++)
$select .= '<option value="' . $a . '">' . $a . '</option>';
$select .= '</select>';
$form->addElement(new Element_HTML('<div class="pfbc-label"><label>Age</label></div>' . $select . ' - ' . $select . ' years'));

- Andrew

Reply all
Reply to author
Forward
0 new messages