dtwd74916 2018-07-11 08: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 09: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');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部