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 want to add this to an SPListItem HTML field (Multiline text)

<a href="#" onclick="OpenDispPage('Table 1.1', 'table');" >Text</a>

and this is what SharePoint makes out of it when I submit

<a href="#">Text</a>

Is this because my field is multiline and not Full HTML or are there any other constraints I'm missing?

Many thanks

share|improve this question
    
Just so I'm clear, you have a Multiline Text field on a list and when you set an item's property to the html fragment above it reformats it strips out the onclick? –  Rob D'Oria Jul 31 '11 at 16:28

1 Answer 1

up vote 2 down vote accepted

Your not going to be able to do this with the Multiline Text field type. Anything other than RichTextMode=FullHtml won't even render the contents as HTML (i.e. you won't see the link) and if you set the field to FullHtml the HTML is altered when the item is saved...this happens with pretty much any implementation of the InputFormTextBox control.

One possible workaround is to put your javascript (...OpenDispPage) into an HTML file that you drop in the 14\Template\Layouts and then reference it in a Hyperlink field instead of Multiline field. So something like this for the URL in the Hyperlink field:

http://sharepointdev:9000/_layouts/yourfolder/test.htm?a=Table%201.1&b=table

Where the arguments to OpenDispPage are passed on the querystring and then the HTML would look something like this:

<html>
<head>
    <title></title>
    <script language="javascript" type="text/javascript">
        OpenDispPage(getQueryString("a"), getQueryString("b"));

        function getQueryString(name) {
            var q = window.location.search.substring(1);
            var qs = q.split("&");
            for (var i = 0; i < qs.length; i++) {
                var parts = qs[i].split("=");
                if (parts[0] == name)
                    return parts[1];
            }

            return null;
        }

        function OpenDispPage(a, b) {
            alert(a + "," + b);
        }
    </script>
</head>
<body>
</body>

I think that's pretty clean, but without knowing exactly what you're trying to do I may be way off.

share|improve this answer
    
Hi Rob, I'm actually writing code to convert Open XML data into HTML, where each section gets it's own SPListitem object in an SPList, the table and figure stylings would be converted into linkbuttons that open up a modaldialogbox pinpointing extracted table/figure data. Because these are just blocks of text and not seperated it would all have to fit into one field. In any case, many thanks for your invaluable help, –  Christoffel de Gruyter Aug 1 '11 at 6:53

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.