SoFunction
Updated on 2025-04-13

When using the ckeditor control, a solution to verify whether the input content is empty (repost)

fckeditor Verify whether the content is empty fckeditor Js verification form
The original code code is as follows
Copy the codeThe code is as follows:

<script language = "javascript">
<!--
function checkForm(){
if (document.==""){
alert("Please enter content!");
return false;
}
return true;
}
//-->
</script>
<form name="form1" method="post" action="" onsubmit="return checkForm();">
<FCK:editor basePath="fckeditor/" height="350" >
</FCK:editor>
<input type="submit" name="Submit" value="Publish">
</form>

This is the most common way of writing in our program. Verify whether the content is empty before submission!
After using the editor, when you press the submit button for the first time, you can't get the editor's value. The content has been entered, but the content has no value! We need to click the Submit button again to get the value!
Many people are confused about this question! Some writing uses JS to read HTML content in the input field! However, this only works for all JS versions of fckeditor and does not work for JSP versions! For such a state, we can only blame the fckeditor developers! And too much code is too troublesome, it is not easy to modify its core!
After continuous testing, I have found a method to solve the problem! Let it out first and share it
Rewrite the code as follows
Copy the codeThe code is as follows:

<script language = "javascript">
<!--
function checkForm(){
setTimeout("SendForm()",50);
return false;
}
function SendForm(){
if (document.==""){
alert("Please enter content!");
return;
}
document.();
}
//-->
</script>
<form name="form1" method="post" action="" onsubmit="return checkForm();">
<FCK:editor basePath="fckeditor/" height="350" >
</FCK:editor>
<input type="submit" name="Submit" value="Publish">
</form>

The purpose of modifying it to this is because the editor has monitored the onsubmit event. It is necessary to place the new content into the hidden content after submission. The original verification event has been executed before the content has been placed, so of course the timely content cannot be obtained!

//==============================================

The above content is a repost, but it has been tested by my actual work and is effective.