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 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C