Yii Framework Forum: Ajax Reload On Dropdownmenu Click - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Ajax Reload On Dropdownmenu Click No Request sent Rate Topic: -----

#1 User is offline   Schnodderbalken 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 05-February 13

Posted 08 February 2013 - 02:58 AM

Hey guys,
what I wanna do is to have a page with a Dropdownlist. When a user clicks on a menu entry the next step (also a dropdownmenu) shall be visible (later on there shall be a dependance but right now I ONLY want to DISPLAY the other dropdown menu when the user clicked an entry in the first one).

So that's my code in the view:

echo CHtml::dropDownList('cat0_name','',$list,
    array(
        'prompt'=>'Kategorie wählen',
        'ajax' => array(
            'type'=>'POST',
            'url'=>CController::createUrl('loadcities'),
            'replace'=>'#cat1_name',
            'data'=>array('id'=>'js:this.value', 'step' => 1),
        )));
echo CHtml::dropDownList('cat1_name','', array(), array('style'=>'display:none;','prompt'=>'Select Stuff'));
echo CHtml::dropDownList('cat2_name','', array(), array('style'=>'display:none;','prompt'=>'Select Stuff'));


What I've tried to do is to replace a dropdownlist with invisible style with a dropdownlist that has my content.
The controller code:

   public function actionLoadcities()
    {
        /*$data=CnfCategory::model()->findAll('id=:id',
            array(':id'=>(int) $_POST['id']));
        $data=CHtml::listData($data,'id','cat_name');*/

        $models = CnfCategory::model()->findAll();
        $data = CHtml::listData($models,
            'id', 'plural');

        $step = $_POST['step'];
        //$step=0;

        echo CHtml::dropDownList('cat'.$step.'_name','',$data,
            array(
                'prompt'=>'Kategorie wählen ',
                'ajax' => array(
                    'type'=>'POST',
                    'url'=>CController::createUrl('loadcities'),
                    'replace'=>'#cat'.($step+1).'_name',
                    'data'=>array('id'=>'js:this.value', 'step' => $step+1),
                )));
        }


What is going wrong here? When I try to do this and inspect the page with firebug no request is called after I click on an entry in the second dropdown menu. If I set the step to 0 (which i commented here) there is at least a post request but nothing happens :( that's very weird.
I hope some of you can help me with this!! :) Even if you know a better method how to do that I would really like to know what's the problem here.
0

#2 User is offline   Schnodderbalken 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 05-February 13

Posted 08 February 2013 - 12:02 PM

Or if nobody knows what's wrong there: what alternative solution is there for having a dropdown menu which displays elements on click? How would you have implemented it?
0

#3 User is offline   Schnodderbalken 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 05-February 13

Posted 09 February 2013 - 11:27 AM

I would be really thankful for an answer :mellow:
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users