title: Dynamic dropdowns with jquery and php
body: <p>i need to know how to keep the states of each dynamically created dropdowns via jquery.</p>
  
  <p>My scenario is like this, i have an option to user to select a date and based on selected date a dropdown is generated. lets say user generated 2 dats and below 2 dropdowns are dynamically generated with the help of jquery.</p>
  
  <pre><code>&lt;select id="dd1"&gt;
    &lt;option value="option1"&gt;option 1&lt;/option&gt;
    &lt;option value="option2"&gt;option 2&lt;/option&gt;
    &lt;option value="option3"&gt;option 3&lt;/option&gt;
  &lt;/select&gt;
  
  &lt;select id="dd2"&gt;
    &lt;option value="option5"&gt;option 5&lt;/option&gt;
    &lt;option value="option8"&gt;option 8&lt;/option&gt;
    &lt;option value="option9"&gt;option 9&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>What i am concerned about is, since these are dyamically created ones i need to keep the same when a form is submitted with erros. so i have done that part but i cannot understand <strong>how to get the previously selected values when form/page is submitted with errors</strong> ?</p>
  
  <p>for example, in dd, if user has selected <strong>option 1</strong> and when the form is submitted with erros it should generate the same dropdown and select it the last selected value which is <strong>option 1</strong> for dd1</p>
  
  <p>any quickly reply is highly appreciated. its a store stopper now. </p>
  
  <p>My yii code is like below.</p>
  
  <pre><code>&lt;?php echo CHtml::activeLabelEx($cssAtapsClient, 'outgoing_call_dates'); ?&gt;
  </code></pre>
  
  <p>And there is a calender in a popup which sets the value of above text box and loads the dynamic dropdowns as highlighted.</p>
  
  <p><img src="https://i.stack.imgur.com/jajrd.png" alt="enter image description here"></p>
  
  <p>Each dynamically added dropdown has a naming convention like below. (select name='CSSAtapsClient[client_time_window][0]')</p>
  
  <pre><code>CSSAtapsClient[client_time_window][0]
  CSSAtapsClient[client_time_window][1]
  CSSAtapsClient[client_time_window][2]
  CSSAtapsClient[client_time_window][3]
  </code></pre>
  
  <p>Wondering how to save the data via PHP ?</p>