doufu6196 2014-12-19 10:48
浏览 47
已采纳

文本编辑器(ckeditor)的Javascript验证无效

I have made the coding of javascript validation for editor(i am using ckeditor).It is not working properly.i.e when i am going to submit the form at first the alert box is coming as the editor is empty but when i am adding some content and going to validate it ,still the alert box is coming.After it everything goes fine.But i want that the alert box will come once ,when the editor field is empty.So please suggest me.Below is my coding.Thank you.

<script type="text/JavaScript">
 function validate()

 { 

        var descrip = document.getElementById("description").value;

if(descrip  == "") {
        alert("Please Enter partner description");
         document.getElementById("description").focus();
         document.getElementById("description").style.borderColor="#fd00d6";
         return false;  
    }

  }
</script>
<script src="ckeditor/ckeditor.js"></script>

<form role="form" action="" method="post" enctype="multipart/form-data" onsubmit="return validate();">

    <div class="box-body">


        <div class="form-group">

            <label for="exampleInputEmail1">Partner Description</label>

            <textarea id="description" name="description"   rows="10" cols="80" class="ckeditor" ><?php echo $_REQUEST['description']; ?> </textarea>

        </div>

    </div>
    <div class="box-footer">

        <button type="submit" class="btn btn-primary" name="add_partner">Submit</button>

    </div>
</form>

  • 写回答

1条回答 默认 最新

  • dongzhong8691 2015-09-29 07:39
    关注

    After reserching a lot ,finally i have found the solution for it. Instead of using

    var descrip = document.getElementById("description").value;
    

    if we use

    var get_desc =  CKEDITOR.instances['description'].getData();
    

    Then we can get the accurate result of that text editor associate field. when editor is empty ,it will return null ,otherwise the the editor value it self. Here we can simply get the (get_desc) ,according to which we can validate the field. Its working fine.I have tested it .Thank you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真
  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?
  • ¥15 YOLOv8obb获取边框坐标时报错AttributeError: 'NoneType' object has no attribute 'xywhr'
  • ¥15 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)