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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog