Wednesday, July 15, 2009

Client side validation for rich text field in SharePoint

I have faced lot of problem in validating a rich text box in SharePoint through JavaScript. Problem is that it does not recognize the text present in the rich text box.

Here is the solution for validating the rich text box.

function validateComments()
{
//debugger;
var Comment = getTagFromIdentifierAndTitle('textarea','TextField','Comment');
var docEditor=RTE_GetEditorDocument(Comment.id);
if (null==docEditor)
return;
strHtml=docEditor.body.innerHTML;
//alert(strHtml);
if(strHtml !="" && strHtml !="
")
{
return true;
}
else
{
alert('Please enter your comment in the box above');
return false;
}
return true;
}

2 comments:

  1. This is great info. I have a question regarding the validation of cross fields. I would like to have a drop down validation where user selects A, then comment field must flag as required. If user selects B, then comment field is not requried.

    Can you help?

    ReplyDelete