title: How to change a value in hidden field from a modal
body: <p>Having a modal with the Terms and Conditions, I need to change the hidden input field value, (name="agree") which is outside the modal, from "no" to "yes" if user accept the terms by clicking the Accept (Acepto) button.
  The reason for doing this is that the form can be sent with the acceptance of the Terms and Conditions.
  Many Thanks in advance.</p>
  
  <p>This is my code (its not working, the value of the input field "agree" never changes):</p>
  
  <pre><code>&lt;form id="formced" ... &gt;
  ....
  &lt;div class="form-group"&gt;
          &lt;button type="button" class="btn btn-default" data-toggle="modal" data-target="#termsModal"&gt;Acepto los Términos y Condiciones &lt;/button&gt;
  &lt;/div&gt;                              
  &lt;!-- Terms and conditions modal --&gt;
  &lt;div class="modal fade" id="termsModal" tabindex="-1" role="dialog" aria-labelledby="Términos y Condiciones" aria-hidden="true"&gt;
  &lt;div class="modal-dialog modal-lg"&gt;
      &lt;div class="modal-content"&gt;
          &lt;div class="modal-header"&gt;
              &lt;h3 class="modal-title"&gt;Términos y Condiciones&lt;/h3&gt;
          &lt;/div&gt;
          &lt;div class="modal-body"&gt;
          &lt;p&gt;TERMINOS Y CONDICIONES ...&lt;/p&gt;
          &lt;/div&gt;
          &lt;div class="modal-footer"&gt;
              &lt;button type="submit" class="btn btn-primary" id="agreeButton" data-dismiss="modal"&gt;Acepto&lt;/button&gt;
              &lt;button type="button" class="btn btn-default" id="disagreeButton" data-dismiss="modal"&gt;No Acepto&lt;/button&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;input type="hidden" name="agree" value="no" /&gt;
  
  &lt;script&gt;
      $(document).ready(function() {
      // Update the value of "agree" input when clicking the Agree/Disagree button
      $('#agreeButton, #disagreeButton').on('click', function() {
          var whichButton = $(this).attr('id');
          $('#formced')
              .find('[name="agree"]')
                  .val(whichButton === 'agreeButton' ? 'si' : 'no')
                  .end()
      });
  });
  &lt;/script&gt;     
  
  &lt;a class="btn btn-primary btn-md" role="button" onClick="return ParaOtrosNavegadores1();"&gt;Continuar &lt;span class="glyphicon glyphicon-forward" aria-hidden="true"&gt;&lt;/span&gt;&lt;/a&gt;
              &lt;script type="text/javascript"&gt;
                  function ParaOtrosNavegadores1(){
                      document.formced.submit();
                  }
              &lt;/script&gt;
  &lt;/form&gt;
  </code></pre>