dtwd74916 2018-07-11 16:30
浏览 60
已采纳

显示单选按钮选择的内容

I have the code in update() to create a new certificate or update an existign one, and its working.

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).

But its not workign the "alert(registrationTypeId);" shows the registration type id but this "$('#certificate_content').val( certificate[registrationTypeId] );" dont works.

CertificateController update():

 public function update(Request $request){
        $registrationType = RegistrationType::where('id', $request->registrationType);
        $certificate = $registrationType->certificate;

        // if no certificate exists for this type, create it
        if(!$certificate ) {
            $certificate = new Certificate();
        }

        $certificate->content = $request->certificate_content;
        $certificate->save();

        $registrationType->certificate_id = $certificate->id;
        $registrationType->save();

        Session::flash('success','Certificate configured with success.');

        return redirect()->back();
    }

Form in the view:

    <form method="post" class="clearfix" action="{{route('certificates.update', ['conference_id' => $conference->id])}}" enctype="multipart/form-data">
    {{csrf_field()}}
    <div class="form-row">
        <div class="form-group col">
            <label>Certificate</label>
            @foreach($conference->registrationTypes as $registrationType)
                <div class="form-check">
                    <input
                            {{ (old('radiobutton') && old('radiobutton') == $rtype->id) ? 'checked' : '' }}
                            class="form-check-input radio" type="radio" name="registrationType"
                            value="{{ $registrationType->id }}" id="{{$registrationType->id}}">
                    <label class="form-check-label" for="exampleRadios1">
                        Certificate for the registration type "{{$registrationType->name}}"
                    </label>
                </div>
            @endforeach
        </div>
    </div>

    <div class="form-group">
        <label>Configure the certificate for the selected registration type</label>
        <textarea class="form-control" name="certificate_content" id="certificate_content" rows="3">{{ $certificate->content }} {{ old('certificate_content') }} </textarea>
    </div>
    <div>
        <input type="submit" class="btn btn-primary btn" value="Save"/>
    </div>
</form>

jQuery:

<script src="https://cloud.tinymce.com/stable/tinymce.min.js"></script>
<script type="text/javascript">

    var certificate = {};
    @foreach($onference->registrationTypes as $registrationType)
            @if(!$registrationType->certificate)
        certificate[{{ $registrationType->id }}] = '';
    @else
        certificate[{{ $registrationType->id }}] = '{{ $registrationType->certificate->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] );
        });

    });
</script>

@stop
  • 写回答

1条回答 默认 最新

  • 普通网友 2018-07-11 17:09
    关注

    After you initialize the textarea with tinymce use this:

    tinymce.get('certificate_content').setContent('YOUR_CONTENT');
    

    also you can do the same with:

    $(tinymce.get('certificate_content').getBody()).html('HTML_CONTENT');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里