Populating fields from dropdown

Hi,

New to Yii, but loving it so far!! But I have been trying to find a solution to the below.

I have a model catches, and a model venue. When creating a catch, I wish to choose from a dropdown form the venue model (which I have working) and using ajax populate the other fields with the values from the record of the currently selected value in the dropdown.

Catches model




public static function model($className=__CLASS__)

	{

		return parent::model($className);

	}

	

	public function getVenues()

	    { 

	     //this function returns the list of venues to use in a dropdown        

	      return CHtml::listData(venue::model()->findAll(), 'vid', 'name');

	    }

	

	public function getSpecies()

	    { 

	     //this function returns the list of species to use in a dropdown        

	      return CHtml::listData(species::model()->findAll(), 'species_id', 'speciesname');

	    }

	

	public function getVenueDetails()

    	{ 

	     //this function supposedly returns the details of the selected venue

	      return CHtml::listData(venue::model()->findAll(), 'vid', 'name', 'location', 'venuetype', 'country');

	    }



Catches View




	<?php echo CHtml::activeDropDownList($model,'venue_id', $model->getVenues(),array('prompt' => '--Select Venue--'));?>

	

	<div class="row">

		<?php echo $form->labelEx(venue::model(),'location'); ?>

		<?php echo $form->textField(venue::model(),'location'); ?>

		<?php echo $form->error(venue::model(),'location'); ?>

	</div>

	

	<div class="row">

		<?php echo $form->labelEx(venue::model(),'country'); ?>

		<?php echo $form->textField(venue::model(),'country'); ?>

		<?php echo $form->error(venue::model(),'country'); ?>

	</div>

	

	<div class="row">

		<?php echo $form->labelEx(venue::model(),'venuetype'); ?>

		<?php echo $form->textField(venue::model(),'venuetype'); ?>

		<?php echo $form->error(venue::model(),'venuetype'); ?>

	</div>



So in summary, looking to get the record from the venues model and populate the location, country and venue type fields from the currently selected venue_id in the dropdown.

Any help very much appreciated.

Welcome to Yii and the forum.

I think it’s more or less this: Creating a dependent dropdown