title: How to submit only one of hide/show fields data when required - Laravel
body: <p>A form contains multiple fields. One field is "yes/no" dropdown. When yes selected, another dropdown appears. When no selected a text input field appears. 
  Depending on yes/no dropdown one of the fields' data should be submitted to the database. </p>
  
  <p>However, both fields data is sent to the database. But the database wants a string and now it gets an array. Data can be submitted. 
  What should be adapted to prevent this, so only data from the showed field is put through the controller and not also data from at that moment hidden field?</p>
  
  <p>Note: 1 field (input of dropdown) should be filled in, required.</p>
  
  JQuery
  
  <pre><code>    window.onload = function() {
              document.getElementById('ifYes').style.display = 'none';
              document.getElementById('ifNo').style.display = 'none';
      }
      function hideShow() {
          var D = document.getElementById("yesno")
          var Y = document.getElementById('isYes')
          var N = document.getElementById('isNo')
              if (D.selected) {
              if (D.value == "yes"){
                      Y.style.display = 'block';
                  N.style.display = 'none';
                  Y.required = true;
              }
              else{
                      N.style.display = 'block';
                  Y.style.display = 'none';
                  N.required = true;
                  } 
          }
      }
  </code></pre>
  
  HTML
  
  <pre><code>&lt;div class="row"&gt;
      &lt;div class="col-6"&gt; 
            &lt;select name="agree" class="form-control" onchange="hideShow();" id="yesno" required&gt;
  &lt;option&gt;&lt;/option&gt;
                &lt;option id="yes"&gt;Yes&lt;/option&gt;
                &lt;option id="no"&gt;No&lt;/option&gt;
            &lt;/select&gt;
      &lt;/div&gt; 
      &lt;div class="col-6"&gt;
             &lt;select name="type" class="form-control" id="ifYes"&gt;
                      &lt;option&gt;Option 1&lt;/option&gt;
                      &lt;option&gt;Option 2&lt;/option&gt;
                      &lt;option&gt;Option 3&lt;/option&gt;
              &lt;/select&gt;
              &lt;input type="text" id="ifNo" class="form-control input-text" name="type"&gt;
       &lt;/div&gt;
  &lt;/div&gt; 
  &lt;div class="row"&gt;
      &lt;button type="submit" class="btn btn-primary btn-block" style="margin: 10px;"&gt;New&lt;/button&gt;
  &lt;/div&gt;
  </code></pre>