Get Value Ckeditor Jquery hoặc JavaScript trong HTML C# Asp.net MVC, khi mình sử dụng CKeditor, mình muốn người dùng phải nhập dữ liệu vào, khi check bằng code C# thì bình thường, nhưng khi lấy dữ liệu bằng js thì không lấy được. Nó toàn ra NULL không. Bạn nào giúp mình lấy giá trị value của ckeditor bằng js hay javascript như thế nào? giúp mình với. Code của mình như sau: Mã: <div class="form-group"> <label class="control-label">Mô tả công việc</label> <div class="row"> @Html.TextAreaFor(model => model.Description, new { @Id = "Description", @class = "form-control", @rows = "3" }) @Html.ValidationMessageFor(model => model.Description) </div> </div> CKEDITOR.replace("Description", { toolbar: [ { name: 'document', items: ['Source', '-', 'NewPage', 'Preview', '-', 'Templates'] }, { name: 'clipboard', items: ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo'] }, { name: 'basicstyles', items: ['Bold', 'Italic'] }, { name: 'links', items: ['Link', 'Unlink'] }, { name: 'paragraph', items: ['NumberedList', 'BulletedList'] } ], height: ["100px"] }); <button class="btn btn-default"> <span class="glyphicon glyphicon-log-in"></span> Cập nhật </button> Tôi muốn khi click vào button sẽ kiểm tra xem đã nhập hay chưa HTML: $(".btn-default").click(function () { var Description= $("#Description").val(); var strValue = ""; if (Description.trim() == "") { strValue = "Vui lòng điền mô tả công việc"; } if (strValue == "") { return true; } else { alert(strValue); return false; } }); $("#Description").val() không hoạt động hizzz. Giúp mình làm sao để lấy được giá trị của ckeditor jquery
Bạn sử dụng CKEDITOR.instances['IDTextarea'].getData(); HTML: var valueck = CKEDITOR.instances['IDTextarea'].getData(); //Hoặc var valueck = CKEDITOR.instances.IDTextarea.getData(); Sửa của bạn thành như sau: Mã: $(".btn-default").click(function () { var Description= CKEDITOR.instances['Description'].getData(); var strValue = ""; if (Description.trim() == "") { strValue = "Vui lòng điền mô tả công việc"; } if (strValue == "") { return true; } else { alert(strValue); return false; } });
var Description= CKEDITOR.instances['Description'].getData(); like, mình làm được rồi, cảm ơn nhiều lắm