title: Hiding some form elements according to the selected dropdown
body: <p>I wanted to hide the elements of the form according to the selected dropdown menu in that form. I succeed to hide the fields according to that particular field. But when I try to update that particular record, it again load the page with all the fields with entered data. But I need to again select the same menu again after which I get that fields hidden again. I am using PHP for this functionality.</p>
  
  <p>I think it's because I am using on change function of jQuery. Here is the code for that function:</p>
  
  <pre><code>  $(document).ready(function() {
  
      $('#viewpage').on('change',function(){
  
          switch(this.value){
              case '1':
                  $('.Song').show();
                  $('.Videos').hide();
                  break;
              case '2':
                  $('.Videos').show();
                  $('.Song').hide();
                  break;
          }
      })
  });
  </code></pre>
  
  <p>Is there any other function that I can use instead of change function that works almost similar way but give me the required fields only, whenever I try to update that record. also change when I change the option.</p>
  
  <p>-- <strong>The question before this line is solved. Needed solution for the question after this line</strong> --</p>
  
  <p>Also I have some fields that I don't required in 'songs' viewpage like 'story_description', but set "required => true " in my Model. So even I am hiding that field for 'Song', I need to put some default values into it. How can I add the default values, either in my index.php or in 'controller.php'.</p>
  
  <p>here is my piece of code from index.php where I am hiding that element.</p>
  
  <pre><code> &lt;div class="form-group vid_field" &lt;?= $option != 2 ? "" : "style='display:none'"  ?&gt;&gt;
                  &lt;label&gt;Description&lt;/label&gt;
                  &lt;?php echo $model-&gt;Form-&gt;editorFor("description"); ?&gt;
   &lt;/div&gt;
  </code></pre>
  
  <p>Here is my controller file piece of code:</p>
  
  <pre><code> function update_post()
   { 
  
      parent::update_post();
   }
  </code></pre>
  
  <p>I think code for setting default values must be go in controller file. Like we can check if the page selected is Song, than the default value for Description must be="XYZ". I don't know how can we do that. Help appreciated. TIA</p>