Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a Javascript variable that contain HTML code as follows:

 <DIV>Hello World<BR>Welcome to SharePoint Stack Exchange</DIV>

So, how do I insert it into the SharePoint 2007 Multi line text field (The meaning of a SharePoint 2007 Multi Line text field is shown in the picture below)?

enter image description here

For your info, I have tried using SPServices to insert that piece of HTML code but it just cannot insert into the SharePoint text field. However, if I use escape(), I am able to insert into the text field but the text is not what I wanted.

Any Insight?



[Update - Additional Information]

I typed the following into the textarea called "newWordDesc" in CODE A

 <DIV>Hello World<BR>Welcome to SharePoint Stack Exchange</DIV>

and with the help of CODE B, it is supposed to store it into a field called "Description" inside SharePoint 2007.

CODE A - HTML TextArea using Javascript

document.write('<textarea id="newWordDesc" wrap="soft"></textarea>');   

CODE B - SPservices

$(document).ready(function() {

        CreateNewItem($("#newWordDesc").val());

        function CreateNewItem(newWordDesc) {
            $().SPServices({
                operation: "UpdateListItems",
                async: false,
                batchCmd: "New",
                listName: "MyList",
                valuepairs: [["Description", newWordDesc]],
                completefunc: function(xData, Status) {
                   $("#responseStatus").html(Status);
                   $("#responseXML").text(xData.responseXML.xml);

                }
            });
        }

Would appreciate if any insight provided.

share|improve this question
    
From your title.. it sounds like you're trying to insert JavaScript into the field? Or is it just plain HTML? Anyways... I'm guessing your SPServices call isn't working correctly.. have you see this page? spservices.codeplex.com/… –  Kit Menke Nov 3 '11 at 13:50
    
Hi Kit, I tested with the plain non-HTML, just normal textarea, it work quite fine but I tried some solution using javascript rich text editor (such as CLEditor), it seems that the whole textarea (that contain those HTML formatting) cannot be insert into SPServices. I have already gone thru the link you provided and appreciate your comments. –  Larry Morries Nov 8 '11 at 9:07

2 Answers 2

You can easily use jQuery to push the value of your variable into the field. Say your field had a title of "MyTextField", you'd do something like $("textarea[title='MyTextField']").append(myVar); if you wanted to append the text, or $("textarea[title='MyTextField']").html(myVar); if you wanted to replace whatever was in the field with the value of your variable. Obviously you may have to tweak the selector to get it right in your environment (I'm trying to think back to what the DOM around multiline fields looks like in 2007). You can use the DOM explorer in the Chrome debug tools, or IE Dev tools to help you build the correct selector, but once you have that it should be a simple jQuery append() or html() call.

I believe multiline fields are rendered as textareas, not input fields (and I just powered down my VM so I can't validate that). If it is a textarea, remember that text areas use the format of <textarea name="x">My Value</textarea> as opposed to an input which uses <input name="x" value="My Value"/>. As such, you should use append() or html() as opposed to val(), since there is no value attribute.

share|improve this answer
    
Hi webdes03, I am looking on how to insert html formatting from a javascript rich text plugin on a html textarea and insert into the sharepoint 2007. –  Larry Morries Nov 8 '11 at 9:08

To get the content of a textarea, you need to use text(), not val():

$("#newWordDesc").text()

Not sure if it helps, but I have a working example of textarea with tags on this page, feel free to look at the source code:

http://usermanagedsolutions.com/SharePoint-User-Toolkit/Pages/Easy-Tabs-v5.aspx

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.