开发者

CKEditor iframe-based plugin and how to return radio value

I have created an iframe-based plugin for CKEDitor using CKEDITOR.dialog.addIframe and want the user to select a radio value, which will be returned to the editor. I am using the code below to try and return the value.

<form name="form1">
    <label><input type="radio" name="field_name" value="[value one]" id="field_name_0" onclick="return get_radio_value()" />value one</label><br />
    <label><input type="radio" name="field_name" value="[value two]" id="field_name_1" onclick="return get_radio_value()" />value two</label><br />
    <label><input type="radio" name="field_name" value="[value three]" id="field_name_2" onclick="return get_radio_value()" />value three</label><br />
</form>
<script language="javascript">
function get_radio_value()
{
    for (var i=0; i < document.form1.field_name.length; i++)
    {
        if (document.form1.field_name[i].checked)
        {
            var rad_val = document.form1.field_name[i].value;
            //alert(rad_val); //this works using onclick
        }
    }
}

var CKEDITOR = window.parent.CKEDITOR;

var okListener = function(ev) {
   this._.editor.insertHtml('<div class="custom_form">'+rad_val+'</div>');
   CKEDITOR.dialog.getCurrent().removeListener("ok", okListener);
};

CKEDITOR.dialog.getCurrent().on("ok", okListener);
</script>

I also tried 开发者_如何学运维the simple:

var form_value = document.form1.field_name.value;
this._.editor.insertHtml('<div class="custom_form">'+form_value+'</div>');

but this returned "undefined"

Any help or ideas would be appreciated?

Note: Form field values are dynamically created via PHP and fed from a MySQL database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜