1
votes

I have a multi line text column in my Sharepoint 2010 custom list grid. My columns are (EmployeeName, EmployeeIDNumber, EmailLink). EmailLink column is a multi line text field where I have an Anchor tag:

<a href="website.com">John Doe</a>

I want to dynamically populate the Text value of the Anchor tag with the value from EmployeeName.

I have tried adding javascript to the HTML Editor of the EmailLink column. When I try to save, Sharepoint 2010 strips the added javascript including the Script tag.

This is how I see the solution working:

<a href="website.com" id="myEmailID">John Doe</a>

<script>
  function onLoad(){
    var rowData = SomeSharepointMethod();
    Document.GetElementByID("myEmailID").innerHTML = rowData["EmployeeName"];
  }
</script>

If it is possible, is there a Sharepoint documentation or method that accomplishes the goal of reading all data from that row?

3

3 Answers

1
votes

Perhaps you might use a calculated column in your list to build your hyperlink, and then surface this column in your view. I did a quick search for an example and pulled one off the top here that applies to SharePoint 2010.

However, there are issues with this approach in later versions of SharePoint (2013+). Checkout this posting for another approach that might be useful.

Additionally, putting your script in a content editor web part, or a script editor web part if available in 2010 may help preserve your JavaScript.

I hope this helps, cheers!

0
votes

As pointed out by dlbrandt, which I think is the best answer to Your question the HTML makrup in calculated fields are not supported as it was not Microsoft intention to use those fields this way -> link

The best option i this case will be a jsLink attached to this column and with some javascript logic that changes the behavior of this filed in new/edit item forms and quick edit mode of list -> jsLink tips

0
votes

We can use jQuery code to achieve it, add the code into content editor web part in edit form page.

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
    var employeeName=$("input[title='EmployeeName']").val();
    var emailLink=$(".ms-standardheader:contains('EmailLink')").closest("td").next().find("div[class^='ExternalClass'] a"); 
    $(".ms-standardheader:contains('" + fieldName + "')").closest("tr").find("input[id$='TextField_spSave']").val("<a href='"+emailLink.attr("href")+"'>"+employeeName+"</a>");
});
</script>