title: How do I use ajax/jquery in yii to add rows to another table and use these values as foreign key in a form?
body: <p>I have this form (I used crud generator and model generator):</p>
  
  <p>Create Pig</p>
  
  <p>[Name]</p>
  
  <p>[Breed]</p>
  
  <p>[Sickness] [Add sickness]</p>
  
  <p>How do I make add sickness create a new textfield everytime I click it? I already have a table for the multivalued sicknessid, I just need to access that  table and add all the sicknesses, use one same id so I can use it as foreign key in the  table.</p>
  
  <pre><code>&lt;?php
  /* @var $this PigController */  
  /* @var $model Pig */
  /* @var $form CActiveForm */
  ?&gt;
  &lt;div class="form"&gt;      
  &lt;?php $form=$this-&gt;beginWidget('CActiveForm', array(
      'id'=&gt;'pig-form',
      'enableAjaxValidation'=&gt;true,
  )); ?&gt;
  
      &lt;p class="note"&gt;Fields with &lt;span class="required"&gt;*&lt;/span&gt; are required.&lt;/p&gt;
  
      &lt;?php echo $form-&gt;errorSummary($model); ?&gt;
  
      &lt;div class="row"&gt;           
          &lt;?php echo $form-&gt;labelEx($model,'name'); ?&gt;                                
          &lt;?php echo $form-&gt;dropDownList($model,'name');?&gt;
      &lt;?php echo $form-&gt;error($model,'name'); ?&gt;      
      &lt;/div&gt;
  
      &lt;div class="row"&gt;
          &lt;?php echo $form-&gt;labelEx($model,'breed'); ?&gt;
          &lt;?php echo $form-&gt;dropDownList($model,'breed', $model-  &gt;getBreedOptions()); ?&gt;
          &lt;?php echo $form-&gt;error($model,'breed'); ?&gt;
      &lt;/div&gt;
  
      /*
      ENTER CODE FOR SICKNESS HERE
      */
      &lt;div class="row buttons"&gt;
          &lt;?php echo CHtml::submitButton($model-&gt;isNewRecord ? 'Create' : 'Save'); ?&gt;     
      &lt;/div&gt;
  
  &lt;?php $this-&gt;endWidget(); ?&gt;
  
  &lt;/div&gt;&lt;!-- form --&gt;
  </code></pre>