I'm using the Kohana PHP framework, not very familiar with Kohana and only a novice with PHP and javascript. I'm working on a project where I have a form::dropdown filled with a list of categories and another dropdown (second one using multiple selections) which needs to be filled dynamically based on which of my categories in the first dropdown is selected. So I know I need an 'onchange' function, but not sure how to include it. And if my javascript function should go anywhere specifically. Below is my form::dropdown definition for the first dropdown. Any help would be appreciated. Thanks.

<?=form::dropdown(array('name' => 'category_id', 'class' => 'input-select'), $categories, $members)?>

Recommended Answers

All 7 Replies

You can include it in the array:

<?=form::dropdown(array('name' => 'category_id', 'class' => 'input-select', 'onclick' => 'yourFuncion()'), $categories, $members['category_id'])?>

You can include it in the array:

<?=form::dropdown(array('name' => 'category_id', 'class' => 'input-select', 'onclick' => 'yourFuncion()'), $categories, $members['category_id'])?>

Ok, no error, but something is either wrong with my javascript function or my function in my controller that deals with all this. I'm thinking my javascript function because it's passing an undefined value to the controller.

Ok, I was missing my parameter in my call to the javascript onchange function... so the value of the selected index is getting passed. BUT, my dropdown is resetting to the first index and not staying at the index I select. What am I missing now?

After looking in the documentation, looks like the syntax for form:dropdown is:

form::select($name, $values_array, $selected_id, $properties_array);
<?=form::dropdown('category_id', $categories, $members['category_id'], array('class' => 'input-select', 'onclick' => 'yourFuncion()'))?>

Doing it this way:

<?=form::dropdown('category_id', $categories, $members['category_id'], array('class' => 'input-select', 'onclick' => 'yourFuncion()'))?>

Selecting a new index in my dropdown keeps my selected dropdown index (which I want) but does not call my javascript function or refresh my 2nd dropdown multiple list (which I also need).

Doing it the previous way:

<?=form::dropdown(array('name' => 'category_id', 'class' => 'input-select', 'onclick' => 'yourFuncion()'), $categories, $members['category_id'])?>

My second dropdown multiple list is refreshed (which I want), but the first dropdown list does not keep the selected index (which I need).

So I'm still having issues.

The first way is the correct one. The second select is not filled because onclick is never called. To fill it you should check with javascript if an element is selected from the first select box and fill the second one.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.