在javascript中检索富文本框sharepoint

时间:2011-02-02 12:36:56

标签: javascript sharepoint sharepoint-2007 richtextbox sharepoint-workflow

我有CustomNewForm用于在sharepoint列表中插入项目。

字段是“Reason”和“Reason OverView”;多行富文本字段。我需要将一些文本从“Reason”复制到“Reason Overview”。(子字符串) 我试图通过工作流完成这项工作,但无法找到获取表单字段的子字符串的解决方案。

我试图从javascript中的“Reason”字段中获取值;但无法这样做。

我的代码::(不工作)

<script type="text/javascript">
function PreSaveAction() 
{ 
    var Reason = getTagFromIdentifierAndTitle("textarea","TextField","Reason");  
    var Original = getTagFromIdentifierAndTitle("textarea","TextField","Reason Overview"); 
    alert('Hi');
    Original.innerHTML=Reason.innerHTML;
    return true;
}

function getTagFromIdentifierAndTitle(tagName, identifier, title) 
{
    var len = identifier.length;

    var tags = document.getElementsByTagName(tagName);

    for (var i=0; i < tags.length; i++) 
    {
        var tempString = tags[i].id;

        if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) 
        {
            return tags[i];
        }
    }
        return null;
}
</script>

有什么方法可以做到这一点?

1 个答案:

答案 0 :(得分:3)

我用这个

解决了
<script type="text/javascript">
function PreSaveAction() 
{ 
    var Reason = getTagFromIdentifierAndTitle("textarea","TextField","Reason");  
    var Original = getTagFromIdentifierAndTitle("textarea","TextField","Reason Overview"); 
    var reasonText = RTE_GetEditorDocument(Reason.id);

    var reasonOverviewText = reasonText.body.innerText;
    if(reasonOverviewText.length>=20)
    {
        reasonOverviewText = reasonOverviewText.substring(0,20)+'......';
        Original.innerText = reasonOverviewText;
    }
    else
    {
        Original.innerText = reasonOverviewText;
    }
    return true;
}

function getTagFromIdentifierAndTitle(tagName, identifier, title) 
{
    var len = identifier.length;

    var tags = document.getElementsByTagName(tagName);

    for (var i=0; i < tags.length; i++) 
    {
        var tempString = tags[i].id;

        if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) 
        {
            return tags[i];
        }
    }
        return null;
}
</script>