title: Show the content on radio button selection
body: <p>I have the code in update() to create a new certificate or update an existign one, and its working.</p>
  
  <p>But then I want that when the user select a specific registration type (radio button), how to show in the textarea the content of the certificate associated with that selected registration type (radiobutton).</p>
  
  <p>But its not workign the "alert(registrationTypeId);" shows the registration type id but this "$('#certificate_content').val( certificate[registrationTypeId] );" dont works.</p>
  
  <p>CertificateController update():</p>
  
  <pre><code> public function update(Request $request){
          $registrationType = RegistrationType::where('id', $request-&gt;registrationType);
          $certificate = $registrationType-&gt;certificate;
  
          // if no certificate exists for this type, create it
          if(!$certificate ) {
              $certificate = new Certificate();
          }
  
          $certificate-&gt;content = $request-&gt;certificate_content;
          $certificate-&gt;save();
  
          $registrationType-&gt;certificate_id = $certificate-&gt;id;
          $registrationType-&gt;save();
  
          Session::flash('success','Certificate configured with success.');
  
          return redirect()-&gt;back();
      }
  </code></pre>
  
  <p>Form in the view:</p>
  
  <pre><code>    &lt;form method="post" class="clearfix" action="{{route('certificates.update', ['conference_id' =&gt; $conference-&gt;id])}}" enctype="multipart/form-data"&gt;
      {{csrf_field()}}
      &lt;div class="form-row"&gt;
          &lt;div class="form-group col"&gt;
              &lt;label&gt;Certificate&lt;/label&gt;
              @foreach($conference-&gt;registrationTypes as $registrationType)
                  &lt;div class="form-check"&gt;
                      &lt;input
                              {{ (old('radiobutton') &amp;&amp; old('radiobutton') == $rtype-&gt;id) ? 'checked' : '' }}
                              class="form-check-input radio" type="radio" name="registrationType"
                              value="{{ $registrationType-&gt;id }}" id="{{$registrationType-&gt;id}}"&gt;
                      &lt;label class="form-check-label" for="exampleRadios1"&gt;
                          Certificate for the registration type "{{$registrationType-&gt;name}}"
                      &lt;/label&gt;
                  &lt;/div&gt;
              @endforeach
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          &lt;label&gt;Configure the certificate for the selected registration type&lt;/label&gt;
          &lt;textarea class="form-control" name="certificate_content" id="certificate_content" rows="3"&gt;{{ $certificate-&gt;content }} {{ old('certificate_content') }} &lt;/textarea&gt;
      &lt;/div&gt;
      &lt;div&gt;
          &lt;input type="submit" class="btn btn-primary btn" value="Save"/&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>jQuery:</p>
  
  <pre><code>&lt;script src="https://cloud.tinymce.com/stable/tinymce.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  
      var certificate = {};
      @foreach($onference-&gt;registrationTypes as $registrationType)
              @if(!$registrationType-&gt;certificate)
          certificate[{{ $registrationType-&gt;id }}] = '';
      @else
          certificate[{{ $registrationType-&gt;id }}] = '{{ $registrationType-&gt;certificate-&gt;content }}';
      @endif
      @endforeach
  
      $(function() {
          $('.radio').change(function() {
              var registrationTypeId = $('input[name=registrationType]:checked').val();
              alert(registrationTypeId); // shows the registration type id
              $('#certificate_content').val( certificate[registrationTypeId] );
          });
  
      });
  &lt;/script&gt;
  
  @stop
  </code></pre>