基于CKEditor iframe的插件以及如何返回无线电值

时间:2011-10-11 00:21:36

标签: ckeditor

我使用CKEDITOR.dialog.addIframe为CKEDitor创建了一个基于iframe的插件,并希望用户选择一个无线电值,该值将返回给编辑器。我正在使用下面的代码尝试返回值。

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

我也尝试过这么简单:

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

但是这返回了“未定义”

任何帮助或想法都会受到赞赏吗?

注意:表单字段值是通过PHP动态创建的,并从MySQL数据库中提供。

0 个答案:

没有答案
相关问题