Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8051609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:20:21+00:00 2026-06-05T07:20:21+00:00

I am doing a yii web application i have a drop down list that

  • 0

I am doing a yii web application
i have a drop down list that should be dependent on another , i use ajax however it doesnt work.
ive seen the yii tutorial for dependent drop downs and searched everywhere.
http://www.yiiframework.com/wiki/24
this is my main drop down list:

<div class="row">
    <?php echo $form->labelEx($model, 'sourceID'); ?>
    <?php
    echo $form->dropDownList($model, 'sourceID', CHtml::listData(Sources::model()->findAll(), 'sourceID', 'name'), array('empty' => 'select source'), array(
        'ajax' => array(
            'type' => 'POST',
            'url' => CController::createUrl('reservations/atest'),
            'update' => '#meal'
        )
            )
    );
    ?>
    <?php echo $form->error($model, 'sourceID'); ?>
</div>    

this is the dependent drop down list :

<div  class="row">
    <?php echo $form->labelEx($model, 'meal'); ?>
    <?php echo $form->dropDownList($model, 'meal', array()); ?>
    <?php echo $form->error($model, 'meal'); ?>
</div>    

this is my controller action:

  public function actionAtest() {

    $data = Sources::model()->findAll();

    $data = CHtml::listData($data, 'sourceID', 'name');

    foreach ($data as $value => $name) {
        echo CHtml::tag('option', array('value' => $value), CHtml::encode($name),true);
    } }

also, i added the action to the access rules.
any help is appreciated ,
thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:20:21+00:00Added an answer on June 5, 2026 at 7:20 am

    You placed the ajax option after the htmlOptions. Here is the modified code

    <div class="row">
        <?php echo $form->labelEx($model, 'sourceID'); ?>
        <?php
        echo $form->dropDownList($model, 'sourceID', CHtml::listData(Sources::model()->findAll(), 'sourceID', 'name'), array('empty' => 'select source','ajax' => array(
                'type' => 'POST',
                'url' => CController::createUrl('reservations/atest'),
                'update' => '#meal'
           )
          )
        );
        ?>
        <?php echo $form->error($model, 'sourceID'); ?>
    </div>   
    

    And instead of using forms dropdownlist use CHtml::dropDownList for the dependent drop-down.

    echo CHtml::dropDownList('meal','', array());
    

    You can also use CActiveForm::dropDownList but in that case you have to use CHtml::resolveNameId in the update option of ajax

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing an application in Yii Framework.I have progressed to some way like
I am running a PHP/Yii application on Apache. I have tried doing the following:
I have a Yii web service actionQuery that queries a model based on four
Hello I'm doing file upload with Yii. I have implemented this way and it
Doing a code review I've stumbled over GWM in Java-Spring-GWT web-application. As this product
Doing a redirect to GET after POST. Spring Web should be adding the 'clientId'
I am using mysql with php Yii framework.When doing data modelling I came accross
Doing an ajax get request works as expected using the following code: $.ajax({ type:
Doing my first SL4 MVVM RIA based application and i ran into the following
Doing some jquery animation. I have certain divs set up with an attribute of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.