Monday, October 15, 2012

Read Multiple lines of Text field value using JQuery


To read a value of multiple lines of text from a Edit Form or New Form. Assume Comments is the field name

<script  language="javascript" type="text/javascript" >
function PreSaveAction()
{
   var Comments = getTagFromIdentifierAndTitle("textarea","TextField","Comments");  

   var CommentsText = RTE_GetEditorDocument(Comments.id);
   var CommentsTextValue = CommentsText .body.innerText;
}

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>

Additionally, use the following code to read the selected value of a drop down.

var val =  $("select[title='ChoiceFieldName']").val();

1 comment:

  1. Thanks! It looks this is the newest one on 'get value from multiple lines of text'. I tried this code but returned 'null' value from function call. Do you have idea what's wrong?

    ReplyDelete