0

I have list view which contains 4 columns.

I have Select Country is a calculated column. The formula for the calculated column is:

="<a href='javascript:SelectCountry("&CountryCode&")'>Select Country</a>"

enter image description here

I need the Select Country column as hyperlink as below, using return type of calculated column as Single line of text.

enter image description here

For that I have Used following JavaScript code.

function reformatCalculatedColumnUrl(){
   debugger;
   $(".ms-cellstyle.ms-vb2:contains('href')").each(function(){
      $(this).html($(this).text());
   });
}

I got the expected result as Select Country as hyperlink, but when I click on any one of the Select Country hyperlinks, the following JavaScript error comes up.

enter image description here

Can anybody tell me why this JS error comes up? Is there any alternate way to convert the calculated column with Single line of text as return type to hyperlink?

1

You are not passing a String to your function.

You can also do without displaying the CountryCode or Country as Columns in the View
OR applying JavaScript after the View is displayed

Make your Calculated Column output the correct HTML:

="<A HREF=""javascript:SelectCountry('"&[CountryCode]&"')"">Select "&[Country]&"</A>"

all you have to do to make that work is set the DataType to DateTime
(datatype Number will align the output to the right)

Note: This trick worked for the past 8 years, no longer works in SPOnline Modern Experiences

And beware of all sideeffects when stuffing HTML in SharePoint fields.

Read the Pros and Cons at: http://www.viewmaster365.com/#/How

0

Try to pass parameters with quotes in function.

For example:

SelectCountry('AD')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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