Monday 16 March 2009

Tip of the Day- A JS way to create inline images to display from attachments in a Rich Text Field

Here is a wee Domino related JS tip.

Say you have a RT field into which users can attach files, these will in the natural schemem of things appear as a list of attachments with nice icons to click on. But what if you want to display them but couldn't be arsed coding in the domino bit of the form to get them to display as inline images.

01. Put a DIV tag around your RT field and give it an ID


<div id='imageRT'>[DominoRTField]</div>


03. Create an empty target [div] to display them in


<div id='imageDsp'></div>


04. Create a JS function in the form or page like this

function dspLinks()
{
target = document.getElementById("imageDsp");
imgLinks = document.getElementById("imageRT").getElementsByTagName("a")
for(t=0;t<imgLinks.length;t++)
{
imgLink = imgLinks[t].href;
img = document.createElement("img");
img.src = imgLink;
target.appendChild(img)
}
}


04. Put your dspLinks() function in the onload of the form and voila you have all the images in your RichText field displayed in the target div as well as the normal link icons you get from a RT Field's attachments.

Disqus for Domi-No-Yes-Maybe