2

I am generating options for my dropdown using

// view.php
foreach ($plants as $row):
    $options[$row->plant_id] = $row->plant_name;
endforeach;

and then lower in the HTML part of view.php

//view.php
$js = 'onChange = "plantDateDelete(\'/size/get_dates_for_plant/\'+this.value);"';
echo form_dropdown('plant_id', $options, 'Select', $js);

The dropdown show options OK, but it does NOT show 'Select' as the "selected"/default value. It shows up with the first option of the array instead.

The HTML source also shows 'Select' in form_dropdown was ignored.

I really need this dropdown to show up with 'Select' as default so as to force the user to activate the onChange function.

Any idea what is going on here or how to solve this issue?

2
  • can you show some of the plants~ including Select Commented Mar 1, 2011 at 1:53
  • @shad, thanks for responding, @jacob solved the issue below Commented Mar 1, 2011 at 1:59

1 Answer 1

7

You need to have the default option in your $options array...

So before your foreach, do:

$options = array('Select');

I should add, this will have the value of 0 in the dropdown, but as its the first element in the array it will be selected by default, unless another option is passed as the default value.

If you wanted to explicitly set this value as the default you would pass 0 as the default argument.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.