Note that there are some explanatory texts on larger screens.

plurals
  1. POYii Ajax Update depending dropdown selection
    text
    copied!<p>I have dropdown list where there are five or six items (here items are services). I used here ajax request which updates the id “package_id” from the URL <code>'url'=&gt;$this-&gt;createUrl('servicePackage'),</code> once I select any service item. Till now, I have done successfully. But I want that ajax should use different URL and update different id i.e. “registrationid” if I select 4th number item, otherwise it should update “package_id”. Is it possible?</p> <p>Is it possible?</p> <p>The form is:</p> <pre><code>&lt;div class="form-group"&gt; &lt;?php echo $form-&gt;labelEx($model,'service_id', array('class' =&gt; 'control-label col-lg-4')); ?&gt; &lt;div class="col-lg-8"&gt; &lt;?php echo $form-&gt;dropDownList($model,'service_id',CHtml::listData(Service::model()-&gt;findAll(),'id', 'name'), array( 'class' =&gt; 'form-control', 'prompt'=&gt;'Select a Service', 'ajax' =&gt; array('type'=&gt;'POST', 'url'=&gt;$this-&gt;createUrl('servicePackage'), 'update'=&gt;'#'.CHtml::activeId($model, 'package_id'), // ajax updates package_id, but I want ajax update registration_id if I select item no 4 'data'=&gt;array('service_id'=&gt;'js:this.value'), ))); ?&gt; &lt;/div&gt; &lt;?php echo $form-&gt;error($model,'service_id'); ?&gt; &lt;/div&gt; &lt;div class="form-group" id="packageid"&gt; &lt;?php echo $form-&gt;labelEx($model,'package_id', array('class' =&gt; 'control-label col-lg-4')); ?&gt; &lt;div class="col-lg-8"&gt; &lt;?php echo $form-&gt;dropDownList($model,'package_id',$model-&gt;getServicePackage($model-&gt;service_id),array( 'class' =&gt; 'form-control','prompt'=&gt;'Select a Package', 'ajax' =&gt; array('type'=&gt;'POST', 'url'=&gt;$this-&gt;createUrl('packagePrice'), //url to call. 'update'=&gt;'#price', //selector to update 'data'=&gt;array('package_id'=&gt;'js:this.value'), ))); ?&gt; &lt;/div&gt; &lt;?php echo $form-&gt;error($model,'package_id'); ?&gt; &lt;/div&gt; &lt;div class="form-group" id="registrationid"&gt; &lt;?php echo $form-&gt;labelEx($model,'registration_id', array('class' =&gt; 'control-label col-lg-4')); ?&gt; &lt;div class="col-lg-8"&gt; &lt;?php $registrants = Registration::model()-&gt;findAll(); $data = CHtml::listData($registrants,'id', function($registrants) { return CHtml::encode($registrants-&gt;name.' ('.$registrants-&gt;id.')'); }); echo $form-&gt;dropDownList($model,'registration_id',$data, array( 'class' =&gt; 'required form-control chzn-select', 'prompt'=&gt;'Select a Registrant', 'ajax' =&gt; array('type'=&gt;'POST', 'url'=&gt;$this-&gt;createUrl('Order'), //url to call. 'update'=&gt;'#'.CHtml::activeId($model, 'order_id'), //selector to update 'data'=&gt;array('registration_id'=&gt;'js:this.value'), ) )); ?&gt; &lt;/div&gt; &lt;?php echo $form-&gt;error($model,'registration_id'); ?&gt; &lt;/div&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload