开发者

Retrieving rich text box sharepoint in javascript

I have CustomNewForm for inserting items in the sharepoint list.

The fields are "Reason" and "Reason OverView"; both Multiple Line Rich Text fields. I need to copy some text from "Reason" to "Reason Overview".(A substring) I tried to get this done with workflow but couldn't find a solution to get a substring of a form field.

I am trying to get the value from "Reason" field in javascript; but unable to开发者_JAVA百科 do so.

MY CODE :: (not working)

<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>

Any way to get this done??


I solved it using this

<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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜