0

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)?>

2
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by aquilax
0

You can include it in the array:

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

You can include it in the array:

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

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.

0

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?

0

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()'))?>
0

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.

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.